This blog post suggests patterns for reusing content from modular blocks fields of the Contentstack SaaS content platform. To address multiple possible interpretations of the phrase “reusing modular blocks” in the title:
- This blog post describes how to use data from modular blocks fields of separate entries when rendering or otherwise processing an entry.
- This blog post is about explicit content reuse within a single channel, unrelated to omnichannel delivery.
- To make modular block field definitions reusable between content types, place them in global fields.
Sidenote: for search engine optimization (SEO) of web solutions, an individual piece of content should appear at a single URL. In most cases, content reuse within a web solution does not involve the primary content of an entry or page, but peripheral elements such as promotions, calls to action, presentation components, and other reusable aspects of visitor experience management rather than the main page content body.
Modular blocks allow multiple complex values to appear as nested JSON structures within a single field value rather than storing that data in separate entries. A modular blocks field contains some number of blocks, each of which contains some number of fields. The values in the individual fields within the blocks appear as fields nested within the JSON representation of the modular blocks field value. For more details about modular blocks fields, see:
Reusing all the blocks in a modular blocks field is no different than reusing any other type of field: follow a reference field from another entry that implicitly or explicitly references the entry that contains the field or use a CMS or GraphQL query or other features to retrieve the entries that contain the block to reuse.
One way to make modular blocks reusable is to store them in separate entries. If you want to reuse only a subset of the blocks in a modular blocks field rather than the entire list, you can move that subset to a separate entry. To do so:
- Create separate entries that contain reusable lists of blocks, where such a list may consist of a single block.
- Add a new block definition to the modular blocks field to let the CMS user specify entries that contain lists of blocks.
- In the new block definition, configure a reference field to allow selection of entries of the content type(s) that contain the modular blocks field.
- Update processing logic to follow references from the new type of block to entries that contain the lists of blocks to reuse.
With this approach, each entry can contain its own blocks and reuse blocks from multiple other entries, and the CMS user has control over the order of the blocks.
If it is not practical to use the existing content type that contains the modular blocks fields to store the reusable lists of blocks, then:
- (If it is not already, place the modular blocks field in a global field and update the existing content type to use that global field, so that both content types use the same modular blocks field definition.)
- Create a new content type that contains only the modular blocks field.
- Configure the reference field in the new block type to allow selection of entries of the new content type, whether in addition to the existing content type(s) or not.
In all content types, use the same identifier for the global field that contains the modular blocks field. This rule isn’t specific to modular blocks or reuse of content, but for at least reuse and logical consistency in code: without a specific need for separate identifiers, always give the same global field the same identifier in all content types.
It may be necessary to handle multiple referencing levels, for example following the reference in a block of an entry to a second block that references a third entry that contains additional blocks to process. In this scenario, beware of potential circular references, where an entry can reference a second entry that in turn references the original entry.
One thought on “Reusing Modular Blocks with the Contentstack SaaS Content Platform”