Skip to content

Turning a static block into a dynamic reusable block #1516

@mtias

Description

@mtias

One appealing aspect of blocks is that they lend themselves to become reusable pieces. This will be key for theme customization (think menus, headers, footers, etc) down the road, but it could already be useful in the context of posts, and it may be wise to get the foundation in place.

Examples

  • Say you create a gallery for a post that you also want to display in a page, and you want them to be in sync.
  • Or you create a custom HTML block for a quick bio that you want to repeat in other posts and you want to only have to update it once.
  • Or you insert a quote you want to be a testimonial repeated in different pages... etc.

WordPress at the moment treats galleries like this—you insert the shortcode and it is evaluated at render time. But it would be nice if any block could be turned into such a reusable entity in a way that is clear to the user and not a surprise.

Proposal

  • Every static block has the ability (from the inspector) to become reusable or shared.
  • This stores the block content and name in a specific post type reserved for blocks.
  • Once a block becomes reusable they are listed in the inserter as "shared blocks" or similar.
  • When inserting a shared block the markup is just an HTML comment reference to the block, like dynamic widgets are at the moment.

Shared blocks can get a different outline color:

image

And when updating them the user can be presented with a confirm dialog asking if they want to update across all posts or convert the current instance back to a static block.

Saving flow can be tricky, because we could issue saves through the API separately from saving a post, since the post only has a reference to the content of the block. This is more of a UX question, though, that will affect blocks like "navigation menu" down the road.

cc @aduth @nb @westonruter @jasmussen @melchoyce @iseulde @youknowriad @nylen and anyone interested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] BlocksOverall functionality of blocks[Feature] MediaAnything that impacts the experience of managing media[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Type] EnhancementA suggestion for improvement.[Type] TaskIssues or PRs that have been broken down into an individual action to take

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions