<p>It's probably not possible to get the sections you limited your entries field to from the template and if there's no entry selected that's what you'd need to do.</p>

<p>But what I'd recommend and what's generally a pretty solid approach in such situations is to build an associative array with all the necessary data and loop through that array:</p>

<pre><code>{% set relationsGroups = {
    'entriesField1': 'Heading Relations 1',
    'entriesField2': 'Heading Relations 2',
    'entriesField3': 'Heading Relations 3',
} %}

{% for fieldHandle, heading in relationsGroups %}
    {% set assets = craft.entries({
        relatedTo: {
            sourceElement: entry,
            field: fieldHandle
        }
        order: 'sortOrder',
        limit: null
    }) %}

    {% for asset in assets %}
        &lt;li&gt;{{ heading }}: {{ asset.title }}&lt;/li&gt;
    {% else %}
        &lt;li&gt;{{ heading }}: Empty&lt;/li&gt;
    {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-08-22T15:03:00.950Z
2015-08-22T16:11:16.957Z
2015-08-22T16:11:16.957Z
carlcs
<p>I am using <a href="http://buildwithcraft.com/docs/entries-fields" rel="nofollow">Entries Field</a> to display related content. I have several Entries Field in an article and i also want to display the fields that are empty, but with their section name.... Is this even possible? I am quite new to Craft, so don't know if I am even in a right direction... Help will be highly appriciated!</p>

<pre><code>{% set assets = craft.entries({
  relatedTo: { 
    sourceElement: entry, 
      field: ['entry','entry2','entry3']
    },
    order:     "sortOrder",
    limit:     null
  })  
%}

{% if assets %}
  {% for asset in assets %}
      {% if asset|title %}
        {{ asset.section.name }}: {{ asset.title }}
      {% else }
        {{ asset.section.name }}: Empty
      {% endif }
  {% endfor %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-08-21T01:14:08.263Z
Can you clarify a bit what you are trying to do? Are the different entry fields for different sections, and you want to show the section title even if there are no selected related entries?
Aaron Berkowitz
CC BY-SA 3.0
2015-08-21T05:25:15.583Z
*"display the fields that are empty, but with their section name"* – what do you mean with section name? The field's title? Or did you limit the entries field to one section only and want to show that?
carlcs
CC BY-SA 3.0
2015-08-21T06:07:55.843Z
Yes, that is completely right. I want to show the section name even if there are no selected entries.
Fredrik
CC BY-SA 3.0
2015-08-21T10:28:48.260Z
I could make them as separates Asset Fields in the template and put a header ove hit. But i really want they displayed in an array. Because it could be a lot of sections (not only 3 as now).
Fredrik
<elementcriteriamodel><entries-field>
Multiple Entries fields, show empty ones?
# Multiple Entries fields, show empty ones?

(Asked by: username_0 on 2015-08-20)

I am using Entries Field to display related content. I have several Entries Field in an article and i also want to display the fields that are empty, but with their section name.... Is this even possible? I am quite new to Craft, so don't know if I am even in a right direction... Help will be highly appriciated!
{% set assets = craft.entries({
  relatedTo: { 
    sourceElement: entry, 
      field: ['entry','entry2','entry3']
    },
    order:     "sortOrder",
    limit:     null
  })  
%}

{% if assets %}
  {% for asset in assets %}
      {% if asset|title %}
        {{ asset.section.name }}: {{ asset.title }}
      {% else }
        {{ asset.section.name }}: Empty
      {% endif }
  {% endfor %}
{% endif %}

**Tags:** elementcriteriamodel, entries-field
> **Comments:**
> **username_1**: Can you clarify a bit what you are trying to do? Are the different entry fields for different sections, and you want to show the section title even if there are no selected related entries?  
> **username_2**: *"display the fields that are empty, but with their section name"* – what do you mean with section name? The field's title? Or did you limit the entries field to one section only and want to show that?  
> **username_0**: Yes, that is completely right. I want to show the section name even if there are no selected entries.  
> **username_0**: I could make them as separates Asset Fields in the template and put a header ove hit. But i really want they displayed in an array. Because it could be a lot of sections (not only 3 as now).  

---

## 1 answers

### Answer by username_2 on 2015-08-22. Score: 1 | Accepted answer

It's probably not possible to get the sections you limited your entries field to from the template and if there's no entry selected that's what you'd need to do.
But what I'd recommend and what's generally a pretty solid approach in such situations is to build an associative array with all the necessary data and loop through that array:
{% set relationsGroups = {
    'entriesField1': 'Heading Relations 1',
    'entriesField2': 'Heading Relations 2',
    'entriesField3': 'Heading Relations 3',
} %}

{% for fieldHandle, heading in relationsGroups %}
    {% set assets = craft.entries({
        relatedTo: {
            sourceElement: entry,
            field: fieldHandle
        }
        order: 'sortOrder',
        limit: null
    }) %}

    {% for asset in assets %}
        {{ heading }}: {{ asset.title }}
    {% else %}
        {{ heading }}: Empty
    {% endfor %}
{% endfor %}


---

