Twig conditional render if specific field in array of referenced entities contains text In a Twig template, I'm conditionally rendering a sidebar based on whether custom field content.field_body (Paragraphs entity reference revisions field type) contains any items.
{% if content.field_body['#items'] %}
  &lt;div class=&quot;jump-sidebar mb-5&quot;&gt;
    &lt;h3 class=&quot;text-sans&quot;&gt;In this article:&lt;/h3&gt;
    &lt;ul class=&quot;list-unstyled&quot;&gt;
      {% for item in content.field_body['#items'] %}
        {% if item.entity.field_subhead %}
          &lt;li class=&quot;text-18&quot;&gt;
            &lt;a href=&quot;#{{ item.entity.field_subhead.value | clean_class | trim }}&quot;&gt;{{ item.entity.field_subhead.value | raw }}&lt;/a&gt;
          &lt;/li&gt;
        {% endif %}
      {% endfor %}
    &lt;/ul&gt;
  &lt;/div&gt;
{% endif %}

This worked fine until the requirements changed. :)
Now I need to render this entire sidebar &lt;div&gt; if and only if one of the item.entity.field_subhead fields in the ['#items'] array contains a value.
{{ dump(content.field_body['#items']|keys) }} returns the following:
^ array:2 [▼
  0 =&gt; 0
  1 =&gt; 1
]

So the ['#items'] are a regular numerically-indexed array.
Rephrasing the question, is it possible in Twig to write a conditional that returns true if any key of a multi-value field contains a specific field?
This is further complicated by the fact that there may be different Paragraph types referenced here, and only one of these (the &quot;Section&quot; paragraphs type) will contain entity.field_subhead, but there might be any number of Sections.
Bonus points if whitespace returns false.
EDIT: Thanks @Hudri!
For future reference, the code that worked in my case looked like this:
{# Test every Section for non-empty Subhead #}
{% set render_sidebar = false %}
{% for field_item in node.field_body %}
  {% if field_item.entity.field_subhead %}
    {% if not field_item.entity.field_subhead.isEmpty %}
      {% set render_sidebar = true %}
    {% endif %}
  {% endif %}
{% endfor %}
{# If any Section contains non-empty Subhead, render block #}
{% if render_sidebar %}
  &lt;div class=&quot;jump-sidebar mb-5&quot;&gt;
    {# a bunch of markup #}
  &lt;/div&gt;
{% endif %}
I'd always do data checks on the entity object (in this case node), and not on the render array content. The second part is the magic .entity to get the linked referenced entity from the host's entity reference field:
{% set render_something = false %}
{% for field_item in node.field_entity_reference %}
  {% if not field_item.entity.field_to_check.isEmpty %}
    {% set render_something = true %}
  {% endif %}
{% endfor %}

{% if render_something %}
  &lt;div class=&quot;my_wrapper&quot;&gt;
    ...content...
  &lt;/div&gt;
{% endif %}

Be warned though data behind .entity is usually not cache-safe (but it is cache-safe in this special case with Paragraphs, because their revisioning is directly tied to their host entity)