3

I've created a paragraph type called "text_icon_boxes". It has 19 fields. I've added this paragraph type to one of my content types.

What I'd like to do is customise the display of this paragraph type. I've created a twig template paragraph--text-icon-boxes.html.twig, but the fields display "-1", etc. How do I access the paragraph fields in this twig template?

Here's a small snippet:

<div class="icon-box-left">
  <h2>{{ content.title }}</h2>
  <p>{{ content.text }}</p>
</div>

The twig template is the right one. Twig template suggestions:

<!-- FILE NAME SUGGESTIONS:
   x paragraph--text-icon-boxes--default.html.twig
   * paragraph--text-icon-boxes.html.twig
   * paragraph--default.html.twig
   * paragraph.html.twig
-->

enter image description here

  • 1
    First enable twig debugging to see what template suggestions exist in your HTML source. Be sure to clear caches after adding new files so they are picked up by the application. drupal.org/node/2598914 – Kevin Feb 8 '17 at 21:18
  • I've updated the question with the twig debugging info. Seems like I got the right name. The field__item is empty though. If I remove the twig file, the content does show up. – Pim Feb 8 '17 at 22:06
  • In your theme are you using 'hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables)' to set your new template as the first suggestion? – Rina Feb 8 '17 at 22:45
  • No, I'm not. Trying the first suggestion gives no result either. – Pim Feb 8 '17 at 23:13
  • Could you show the manage fields tab? it seems like the fields are not called correctly, since drupal alwyas adds field_ at the start of fields. – Kimimaruu Feb 9 '17 at 7:10
6

The field variables are not right - they need to correlate to the field name.

Example:

{{ content.field_icon_1 }}

{{ content.field_icon_1_title }}

These are the render arrays you are looking for. {{ content.text }} does not exist.

Also, keep in mind that these render arrays are rendering those fields - you may want to place the markup in those field specific templates.

  • How to access CONTENT_TYPE fields in paragraph field template file ? e.g I want to print node title in paragraph template file, how can I access the content_type fields here. paragraph--FIELD-NAME.html.twig – Zafar S May 27 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.