Skip to content

Paragraph-Item Bundle-specifc templates are never called. #248

@jenlampton

Description

@jenlampton

I'm having a problem perhapx similar to #194, but in my case I cannot get an override for paragraphs-item.tpl.php to work at all.

I have a bundle named section and I can see this in by printing it out in my preprocess hook, as follows:

/**
 * Prepare variables for paragraph-item templates.
 */
function hook_preprocess_paragraphs_item(&$variables) {
  dpm($variables['paragraphs_item']->bundle);
}

But when I create a template file named paragraphs-item--section.tpl.php it is never called.

When I enable theme debug and look at the suggestions for overrides, I see the following:

 FILE NAME SUGGESTIONS:
   x paragraphs-item.tpl.php
   * paragraphs-item--section.tpl.php
   * paragraphs-item--section--paragraphs-editor-preview.tpl.php
   * paragraphs-item--5.tpl.php
   x paragraphs-item.tpl.php

I wonder if the problem is that paragraphs-item.tpl.php appears in here twice, at both ends. This would make that file "win" the selection process, regardless of which way the suggestions are checked.

In my preprocessor, I needed to remove the duplicate suggestion, as follows:

function hook_preprocess_paragraphs_item(&$variables) {
  // Clean up theme hook suggstions.
  $names = array();
  foreach ($variables['theme_hook_suggestions'] as $key => $name) {
    if (!in_array($name, $names)) {
      $names[$key] = $name;
    }
    else {
      unset($variables['theme_hook_suggestions'][$key]);
    }
  }
  unset($variables['theme_hook_suggestion']);
}

I couldn't find where this extra suggestion is being added in paragraphs. Perhaps this is an entity_plus issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions