1

So my 1. file is "_overview-topicTeaser.twig" which is within a matrix:

{% include 'modules/module-squareteaser/_module-squareteaser' with {
  squareTeasers: block.topicTeaserItems.all(),
  squareteaserHeadline: block.topicTeaserItems.one().entryTopicHeadline
} %}

And my 2. file is "_module-squareteaser.twig":

    <div class="squareteaser__wrapper _parent-3-child">
      {% for item in squareTeasers %}

        {% include 'modules/module-squareteaser/_module-squareteaser-item' with {
          headline: squareteaserHeadline
        } %}

      {% endfor %}
    </div>

So i am looping in the 2. file the file "_module-squareteaser-item.twg" and want to put out the "squareteaserHeadline" in the frontend. But it always gives me the same headline from my first teaser in the loop, makes sense to me cause i am using the "one()" when i include the variable "squareteaserHeadline" in the first file. But if i delete the "one()" i get nothing... so how do i get all teasers whith their own headline?

enter image description here

1 Answer 1

1

Can't you fetch all the blocks with block.topicTeaserItems.all()

{% include 'modules/module-squareteaser/_module-squareteaser' with {
  squareTeasers: block.topicTeaserItems.all()
} %}

And then you display the headlines with item.entryTopicHeadline

<div class="squareteaser__wrapper _parent-3-child">
  {% for item in squareTeasers %}
    {% include 'modules/module-squareteaser/_module-squareteaser-item' with {
      headline: item.entryTopicHeadline
    } %}
  {% endfor %}
</div>

A simplified version would look like

<div class="squareteaser__wrapper _parent-3-child">
    {% for item in block.topicTeaserItems.all() %}
        {{ item.entryTopicHeadline }}
    {% endfor %}
</div>
4
  • Sure i could do it with "item.entryTopicHeadline". But i am using the "_module-squareteaser.twig" for multiple includes at different places on the website. So thats why i wanna go with just "squareteaserHeadline", Thought its somehow possible. Commented May 3, 2018 at 14:30
  • You would have to create a new array of headlines by looping through all blocks in your _overview-topicTeaser.twig Commented May 3, 2018 at 14:33
  • And how i do this? :) Commented May 3, 2018 at 15:03
  • This would be a new question, but there are plenty examples how to create an array in twig. twig.symfony.com/doc/2.x/filters/merge.html Commented May 3, 2018 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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