Paragraphs can be used as a way for Content Creation in Drupal. It actually allows the site builders to do their stuff a bit cleanly and for the end users this will be pretty easy to manage the content, meaning people get more control on the Editing side.
Paragraphs is one of the popular modules in Drupal, for handling content. It is more or less very similar to the fields and will provide a wide range of options for layout and grouping of content as people need.
Ideally having all the content via WYSIWYG editor, people can have paragraphs to manage the content on Drupal, basically Site editors can provide a proper structure for a certain feature via the Paragraph and Theme the paragraph well, it means controlling the appearance for the particular component can be done.
Speaking of Components, building the features in a component based approach via the Paragraph, will help Site editore to attach such reusable components in different content node or entities, for example
- Quote (with couple of different views)
- Slideshow (with couple of different views)
- Gallery (with couple of different views)
List grows like this based on the needs of the users or customers.
Lets see, how one can Setup the paragraphs module and Template it at the very basic level.
One needs to have a Drupal core, and we are proceeding with composer based installation of Paragraph, so people to make sure, Drupal is set up with composer, And if you are using Docker or Lando, make sure to install the composer library within them.
1. Install Paragraph module
- You can download the module from this link https://www.drupal.org/project/paragraphs, Currently, I'm using Lando for local setup, so I have run composer with lando.
$ lando composer require 'drupal/paragraphs:^1.14'
./composer.json has been updated
Running composer update drupal/paragraphs
Loading composer repositories with package information
Lock file operations: 2 installs, 0 updates, 0 removals
- Locking drupal/entity_reference_revisions (1.9.0)
- Locking drupal/paragraphs (1.14.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Downloading drupal/entity_reference_revisions (1.9.0)
- Downloading drupal/paragraphs (1.14.0)
- Installing drupal/entity_reference_revisions (1.9.0): Extracting archive
- Installing drupal/paragraphs (1.14.0): Extracting archive
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
Hardening vendor directory with .htaccess and web.config files.
48 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
2. Enable the module
- As any other module enable this module via module page, and on higher environments enable this via configuration sync (Learn more how to manage configurations in Drupal from this link)
3. Create Paragraph Type
- Create a paragraph type via this path (
/admin/structure/paragraphs_type), this form will ask for Label, Icon and Description, Fill all details and Click on Save and Manage fields.
- Add the needed fields to the Paragraph type, for example Quote and Author field.
4. Attach Paragraph type to Node or Entity
- Create an
Entity Reference Revisionsfield on the node/entity type, Select
Paragraphsat the field Type and select an unlimited for the Allowed number of values option.
- Under Reference method, Select Default value, And under the Paragraph types select the needed paragraph types. Then Click on Save settings button.
- Under Manage Form Display, have the default value as
Paragraph (Stable), then Click on Save.
- Under Manage Display, have the default value as
Rendered Entity, then Click on Save.
Now you can use this paragraph from the Admin side by creating content via the Node or Entity the paragraph is attached to. And now lets see how we can design for the User.
By default, the Paragraph module will provide a default template file paragraph.html.twig within the module. One can use this file within the custom theme and proceed with the design stuff. Or can you make template suggestions and create specific template files for a specific display, for more on how to work with template suggestions read this article.
To conclude, this way Site builders or Developers can use the paragraph module in drupal application. Thanks for reading the article, I hope this is helpful. Read more drupal related articles from here.