Skip to content

Paragraphs, Template Files, and Pre processing

Laryn - CEDC.org edited this page Dec 7, 2021 · 2 revisions

There are two template files provided by Paragraphs — paragraphs-item.tpl.php and paragraphs-items.tpl.php. (Notice the second is plural) To change the template of an individual bundle, you would override paragraphs-item.tpl.php.

So if your bundle is "Hero Image with Headline" (machine name: hero_image_with_headline), then your template file would be paragraphs-item--hero-image-with-headline.tpl.php.

For fields within that bundle, you would override field.tpl.php. So, field--field-hero-image.tpl.php and field--field-headline.tpl.php in my example.

Source: Mattbarnes

  • If you are having trouble finding the right filename for your template file, turn on "Theme debug" in the devel module and view the source code around where the Paragraph bundle is displayed. It should show you a variety of options for filenames.
  • Reference: default template files

Pre-processing

Paragraphs item pre-processing can be reliably done with template_preprocess_paragraphs_item() thanks to the good work of @argiepiano.