Paragraphs: How to Manage Irregular Content in Drupal 8
Drupal 8 offers considerable functionality for managing fielded content. Unexpected business needs, however, can result in less-than-ideal workarounds, such as rich text, when time, budget, or data constraints prevent more Drupal-specific solutions, such as Views.
Maintainability can be impacted when rich text is used for unintended purposes, such as alternative page layouts. This is among the reasons why it's essential for developers to guide clients toward better solutions, while carefully curating tools available in the rich text editor.
The Drupal Paragraphs module provides a solution for breaking up, reducing, and managing rich text at the content level.
Want to learn more about Drupal? Sign up for our training!
What are Paragraphs?
Paragraphs are fielded entities that are specific to a single piece of content. Adding Paragraphs to a node is like adding blocks to a region. For example, if a blog post needs a data table inserted into its rich text, rather than embedding something or hard coding it, the following Paragraphs could be added in place of a single rich text field:
- Paragraph type: "Basic Content" - This would contain the first part of the rich text in this example. This Paragraph's type would consist of a single rich text field.
- Paragraph type: "View Content" - This Paragraph's type would have a single "Views Reference" field.
- Paragraph type "Basic Content" - The remaining rich text content would be placed into this paragraph, following the view block containing the data table.
In addition to Paragraphs, it is worth noting that the "Entity Embed" module can allow entities to be embedded inline within rich text content. This can be helpful in reducing complexity of rich text and it is convenient to be able to set the embedded content's view mode.
Paragraphs can also supply settings fields on the content edit form for customizing a page's output. For instance, a "Recent Blogs" paragraph type that displays a view block could have custom settings to control the number of results, teaser to display, and could provide some template-specific logic, such as "title position." This approach provides the flexibility of content-specific customization managed at the content level.
Given that Paragraphs are entities, Paragraphs can also have child paragraphs. For example, a parent Paragraph could act as a general container for different kinds of content, similar to a queue. An example of this might be a grid of media, blog posts, and taxonomy terms, with associated theme-level templates and styles to support this presentation. Although other solutions can do this, this approach is content-specific and takes place on the content edit form.
Tips for Implementing Paragraphs
- Survey site pages to identify repeated use of similar or duplicate content within each page's "content area" where page-specific content is displayed. Then, consider moving those repeated instances of content into blocks or views so that paragraphs can reference that content in the appropriate locations.
- Add a "rich text" Paragraph type as a tool for breaking up rich text when some of its content can be displayed using non-rich text paragraphs.
- If block content is being added above or below the content area for multiple pages via block visibility path settings, consider adding those blocks to those pages via "block reference" paragraphs instead.
- Be sure to review and set permissions when adding new Paragraph types.
Paragraphs is a powerful Drupal module that provides a wide range of possibilities concerning content creation and presentation. Interested in exploring the possibilities for Paragraphs and optimizing the experience of your Drupal site? Contact us today.