Skip to content

Per-page default option values for directives #80

Closed

Description

@choldgraf

Context

There are many times where you want to populate a single page with many Sphinx Design items that all share the same configuration. For example, "I want a list of 10 cards, each of which has a specific margin, padding, outline, or CSS class".

In these cases, there is a lot of toil and boilerplate duplication when adding them, since you have to manually edit the options for each one. It would be helpful if there were a way to define the default configuration of each item once and then re-use it throughout the page.

Proposal

Make it possible to define the default configuration of Sphinx Design components on a per-page level (or at the site-level). There are two ways I could think of to do this:

  1. Use page-level configuration. For example:

    sphinx_design:
       defaults:
          link-button:
     	    :color: primary
     		:outline:
    

    However I don't know that this would be doable in rST...

  2. Set page-level defaults with a directive. For example, perhaps there was a sd-default directive. Inside that directive you could define any arbitrary Sphinx Design objects. It would render them as normal, but would also then set the configuration of each object to be the default for any subsequent objects on the page. e.g.:

    ````{sd-default}
    ```{button-link} foo
    :color: primary
    :outline:
    ```
    ````
    

Tasks and updates

No response

Activity

  1. added
    enhancement
    on Jul 20, 2022
  2. changed the title [-]Per-page default configuration[/-] [+]Per-page default configuration for components[/+] on Jul 20, 2022
  3. chrisjsewell commented on Aug 22, 2022

    @chrisjsewell
    Member

    I think actually this would be more general, and actually easier, to implement this in myst-parser!
    Obviously, this would only then be supported in Markdown/MyST-NB documents, but then well, people should use those 😄

  4. changed the title [-]Per-page default configuration for components[/-] [+]Per-page default option values for directives[/+] on Aug 22, 2022
  5. chrisjsewell commented on Jul 12, 2026

    @chrisjsewell
    Member

    Thanks for this — it directly shaped what became the sd_custom_directives configuration in v0.6.0: you can define a directive once in conf.py (inheriting from e.g. grid-item-card) with your default margin/padding/class options and reuse it everywhere, which addresses the boilerplate concern here. Docs: https://sphinx-design.readthedocs.io/en/latest/get_started.html#creating-custom-directives

    Closing as delivered; if a true per-page override mechanism is still wanted on top of that, happy to consider it in a fresh issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions