• It seems unfathomable to me that the following would not be possible, so I’m hoping that I’m just missing something or not using the right terminology when searching…

    What I would ideally like to accomplish would include all three of the following:

    1. Create something like a block pattern by combining existing/core blocks — this is clearly possible by registering a “block template,” whether by including a file in the /patterns directory of a theme, or via PHP using register_block_pattern. (As an example, take the (extremely common!) design pattern of a “hero” or page header section that combines a Cover Block, Heading block, perhaps a subheading or description using the Heading or Paragraph block, and perhaps a Button block.)
    2. Include the block pattern in the site editor by default when adding a new page/post/CPT, with the inner content editable by the user — this seems to be possible at least when using the PHP register_block_pattern method (by including a blockTypes value as described here — it is however not clear to me whether or not there is an equivalent method when registering the pattern by adding a file to the /patterns folder instead of via PHP?)
    3. The style of the pattern would be editable “globally” from a single/central location. (For example, the “hero section” pattern is in place on dozens of pages, and the site user or developer wishes to increase the vertical padding or minimum height of the Cover block contained in the pattern and have that change apply to all instances of the Pattern across the site.)

    The searching I have done so far is leading me to believe that #1 and #3 are mutually exclusive, in that a Pattern’s style settings cannot be changed programmatically once the pattern has been saved into post/page content (i.e. into the database).

    Is hand-coding a custom dynamic block really the only way to achieve #3 above?? And, if so, is there a way to “custom-code” a dynamic block that retains the ease of point #1 above — is there any way to do it that through copy-pasting markup to incorporate existing/core blocks, or can coding something like a simple repeating hero section only be done “from scratch” via block.json?

Viewing 1 replies (of 1 total)
  • Hi,

    It is correct that as soon as you use a block pattern in a post, it will be copied into the post so any subsequent changes that you make on the block pattern itself won’t be reflected in pages that have already been saved.

    A potential solution could be that you add a unique CSS class to your block patter and do all subsequent styling through a global CSS on the theme, this will affect all blocks that have this CSS class.

    Unfortunately I am unaware of the possibility to add a block pattern by default to a page. You can use Block Templates to define the default content for new posts or CPTs but as far as I know you’d need to specify the block pattern as PHP code instead of HTML.

Viewing 1 replies (of 1 total)
  • The topic ‘“Dynamic Block Patterns”: content editable, but “single source” for design?’ is closed to new replies.