简体   繁体   中英

Drupal 8 Twig looping through a paragraph EntityRevisionItemList

i have a Node which has a field node_field (entity reference revision) which points to a paragraph (can be added 3 times). That paragraph has only 1 field in it, which itself is a entity reference field that points to a node bundle.

I'm trying to loop through each paragraph and each node inside so i can render the entire node (not individual fields), i only want the nodes, don't need to render the paragraph.

Here's my approach in the node.twig.html via the content variable and it works, i get the desired result.

    {% if content.my_field|render %}
        {% for key, item in content.my_field if key|first != '#' %}
        <div class="col-lg-4 col-md-6">
            {{ item }}
        </div>
        {% endfor %}
    {% endif %}

Now i want to do the exact same thing but use the node variable instead of content but i just can't seem to get it to print. Any ideas?

Realy it's depend of the content that you have into the item. If you have devel installed, you could use kint to see the difference between the content of both, the differents variables, etc...

Depends of the element where you are iterating you can render each elements, other times you need get the value of each item (item.getValue()[0]).

I hope that my answer could be enought.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM