Documentation
Paragraphs
Sites built with the Paragraphs module can render their paragraph types as Maya components without writing templates. Go to Appearance > Settings > Maya (or your sub-theme), open Paragraph types, and choose a component for each type. Types without a component render as Drupal would.
Components
| Component | Renders | Parts |
|---|---|---|
| Grid | A maya:card-group: a heading over the referenced items side by side, with "See more results" after the first items if you set a number. |
Items, number of columns, view mode of the items, heading, shaded background |
| Card | A maya:card of the variant you choose, linked to the link field. |
Image, heading, link, body |
| Spotlight | Text and a button beside a large image, like the home page spotlight. Runs edge to edge below 1024px. | Image, heading, link, body |
| Button | A link styled as a button, with an optional heading and text above it. | Heading, link, button text, body (text fields only) |
| Accordion item | A heading that expands to show the text. | Heading, open by default, body |
| Hidden | Nothing, not even an empty grid cell. Use it for spacers and other layout helpers. |
How fields fill the parts
Each part takes the first field that fits it, unless you pick a field in the type's fields settings. Pick None to leave a part empty.
| Part | First field that fits |
|---|---|
| Items | Entity reference revisions (paragraphs), then dynamic entity reference, then any entity reference that is not an image |
| Number of columns | A list or number field with column in its machine name. Values from 1 to 6: 1 column below 768px, at most 2 (3 for 5 or 6) below 1024px. |
| View mode of the items | An Entity reference display field, or one with view_mode or display_mode in its name. Without one, paragraphs use their default view mode and other entities their teaser. |
| Heading | A text field with title or heading in its name, then one with label |
| Shaded background | A field with background in its name. Any value shades the grid. |
| Image | An image field or a media reference |
| Link | A link field. The link text labels the button. A card links to it, and uses its text as the heading when there is no heading field. |
| Button text | A text field with button, text or label in its name. Overrides the link text. |
| Open by default | A boolean field |
| Body | Every other field the paragraph's display shows, in its order. Fields the display hides stay hidden. List, number and boolean fields are treated as settings and left out. A card shows the body as its description. |
Cards also take two settings next to their fields: the card variant (regular, featured, highlight, image above text, or news list item; see maya:card) and the image ratio (1:1 puts the image beside the text of a regular card; 16:9 and 3:2 put it on top, and regular cards show 3:2 as 16:9). Grids take items before "See more results"; leave it empty to show every item. Nodes referenced by a grid render in their view mode as described in Node teasers.
Grids span the content column. Text inside them, and text fields elsewhere in a node, keep to a readable width.
Example
A site with these paragraph types:
| Type | Fields | Component |
|---|---|---|
| Section | Contents (paragraphs), Columns (list: 1-4), Background color (list) | Grid |
| Card | Image (media), Title, Text, Link | Card |
| Hero | Image (media), Title, Text, Link | Spotlight |
| Detail | Label, Text, Open (boolean) | Accordion item |
| Gap | Size (list) | Hidden |
needs no field choices: every part is filled automatically.
Configuration
The mapping is stored in the theme's settings, so it deploys with configuration:
# maya.settings.yml, or mysubtheme.settings.yml
paragraphs:
section:
component: grid
gallery:
component: grid
more: 12
fields:
items: field_images
card:
component: card
variant: regular
image_ratio: '1:1'
A sub-theme needs a schema for its settings to validate. Reuse Maya's in config/schema/mysubtheme.schema.yml:
mysubtheme.settings:
type: maya.settings
Templates
Each component has a template in templates/paragraphs, for example paragraph--maya-grid.html.twig. Override one in a sub-theme to change every paragraph type mapped to that component, or use the type's own suggestion (paragraph--section.html.twig) to change just that type.