0

I've created a custom block type includes a paragraph type field and make it multiple. I've configured this block to display it only on the front page. I have a page--front.html.twig template in my custom theme. What I want to do in my front page template is looping through the paragraph field to get each field item and theming it in custom HMTL.
So what is the correct way to do this?
I've tried block--BLOCKID.html.twig and try this code.

{% for item in content.field_home_page_carousel %}
{{ kint(item.field_home_slide_image) }}
{% endfor %}

but I got nothing.

  • You need to theme the field inside the paragraph and then the paragraph field itself (the container), not the block. – Kevin Dec 10 '17 at 13:59
0

I Agree with Kevin's comment. Focus on theming the block.

Activate your theme's debug mode and view the template suggestions for your block. Add a new template and name it as one of the template suggestions, e.g. block--views-block--more-by-this-author-block-1.html.

It may help to duplicate the original block's code and paste into your new twig file, then find a good place to add your for loop.
Now you can loop through the paragraphs:

{% for item in content.field_home_page_carousel %}
    <p>{{ item.field_home_slide_image }}</p>
{% endfor %}

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.