-
Notifications
You must be signed in to change notification settings - Fork 14
Paragraphs, Template Files, and Pre processing
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.
- If you are having trouble finding the right filename for your template file, turn on "Theme debug" in the
develmodule 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
Paragraphs uses Entity Plus. As @argiepiano notes:
Preprocessing in Entity Plus is confusing. One would logically assume that the following preprocess hook would work:
template_preprocess_paragraphs_item. But no. These preprocessing functions never get called (I suffered through this issue a few times myself!) ... [Y]ou must usehook_preprocess_entity_plusand use if statements to check that you are preprocessing the right template/entity. Eventually this may be something we could fix within Entity Plus.
For example:
/**
* Implements hook_preprocess_HOOK().
*/
function MODULE_preprocess_entity_plus(&$variables) {
if ($variables['entity_type'] == 'paragraphs_item') {
// Do stuff.
}
}