<p>UIDs are not yet usable in queries. You would need to extract the <code>UID</code> of the section from the string then fetch the <code>sectionId</code> to use in your query. </p>

<p>Something like this:</p>

<pre class="lang-twig prettyprint-override"><code>{% for tab in entry.fieldLayout.tabs %}
    {{ tab.name }}
    {% for field in tab.getFields() %}
        &lt;label for="{{ field.handle }}"&gt;{{ field.name }}&lt;/label&gt; &lt;br&gt;
        {% if field.className == 'craft\\fields\\PlainText' %}
        {# field text settings #}
        {% elseif field.className == 'craft\\fields\\Number' %}
        {# field number settings #}
        {% elseif field.className == 'craft\\fields\\Entries' %}

            {% set sources = [] %}

            {# Start our `entries` query #}
            {% set entries = craft.entries %}

            {# Iterate over sources #}
            {% for source in field.sources %}

                {# If All sources is selected in field definition, skip this #}
                {% if source != '*' %}
                    {# Extract UID from the string #}
                    {% set sectionUid = source | replace({'section:': ''}) %}

                    {# Fetch sectionId from UID and push in `sources` array #}
                    {% set sources = sources | merge([craft.app.sections.getSectionByUid(sectionUid).id]) %}
                {% endif %}
            {% endfor %}

            {# If we have `sources` then add to our query, else, fetch everything #}
            {% set entries = sources ? entries.sectionId(sources) : entries %}
            &lt;select name="fields[{{ field.handle }}][]"&gt;
                &lt;option value=""&gt;Choose&lt;/option&gt;
                {% for entry in entries.all() %}
                    &lt;option value="{{ entry.id }}"&gt;{{ entry.title }}&lt;/option&gt;
                {% endfor %}
            &lt;/select&gt;
        {% endif %}
    {% endfor %}
{% endfor %}
</code></pre>

<p>This will cater for multiple sources as well as <em>All</em> being chosen in your field definition</p>

CC BY-SA 4.0
2020-05-08T10:11:06.767Z
2020-05-08T10:11:06.767Z
Oli
<p>I have multiple entries fields that I want to use in the front-end. In the field settings I'll set up a sections source for each field. On the frontend I want a dropdown select box with all the entries from section I'll setup for each entries field. If I'll dump the field sources from the field layout I'll get this:</p>

<pre><code>array(1) {
  [0]=&gt;
  string(44) "section:a0977adf3fd-bd50adf-479cadf-90cd-8d5ef46de79c"
}
</code></pre>

<p>How to get entries related to the section source above? </p>

<pre><code>{% entries = craft.entries.section(field.sources).all() %} // This is not working
</code></pre>

<p>This is the code where I'll need it for some context</p>

<pre><code>{% for tab in entry.fieldLayout.tabs %}
    {{ tab.name }}
    {% for field in tab.getFields() %}
            &lt;label for="{{ field.handle }}"&gt;{{ field.name }}&lt;/label&gt;
            {% if field.className == 'craft\\fields\\PlainText' %}
                {# field text settings #}
            {% elseif field.className == 'craft\\fields\\Number' %}
                {# field number settings #}
            {% elseif field.className == 'craft\\fields\\Entries' %}
                {% set entries = craft.entries.section(field.sources).all() %} 
                {# entries is empty how to fix? #}
                &lt;select name="fields[{{ field.handle }}][]"&gt;
                    &lt;option value=""&gt;Choose&lt;/option&gt;
                    {% for entry in entries %}
                        &lt;option value="{{ entry.id }}"&gt;{{ entry.title }}&lt;/option&gt;
                    {% endfor %}
                &lt;/select&gt;
            {% endif %}
    {% endfor %}
{% endfor %}
</code></pre>

<field><frontend><sources>
How get entries by sources in a frontend fieldlayout?
# How get entries by sources in a frontend fieldlayout?

(Asked by: username_0 on 2020-05-08)

I have multiple entries fields that I want to use in the front-end. In the field settings I'll set up a sections source for each field. On the frontend I want a dropdown select box with all the entries from section I'll setup for each entries field. If I'll dump the field sources from the field layout I'll get this:
array(1) {
  [0]=>
  string(44) "section:a0977adf3fd-bd50adf-479cadf-90cd-8d5ef46de79c"
}

How to get entries related to the section source above? 
{% entries = craft.entries.section(field.sources).all() %} // This is not working

This is the code where I'll need it for some context
{% for tab in entry.fieldLayout.tabs %}
    {{ tab.name }}
    {% for field in tab.getFields() %}
            {{ field.name }}
            {% if field.className == 'craft\\fields\\PlainText' %}
                {# field text settings #}
            {% elseif field.className == 'craft\\fields\\Number' %}
                {# field number settings #}
            {% elseif field.className == 'craft\\fields\\Entries' %}
                {% set entries = craft.entries.section(field.sources).all() %} 
                {# entries is empty how to fix? #}
                
                    Choose
                    {% for entry in entries %}
                        {{ entry.title }}
                    {% endfor %}
                
            {% endif %}
    {% endfor %}
{% endfor %}

**Tags:** field, frontend, sources


---

## 1 answers

### Answer by username_1 on 2020-05-08. Score: 3 | Accepted answer

UIDs are not yet usable in queries. You would need to extract the UID of the section from the string then fetch the sectionId to use in your query. 
Something like this:
{% for tab in entry.fieldLayout.tabs %}
    {{ tab.name }}
    {% for field in tab.getFields() %}
        {{ field.name }} 
        {% if field.className == 'craft\\fields\\PlainText' %}
        {# field text settings #}
        {% elseif field.className == 'craft\\fields\\Number' %}
        {# field number settings #}
        {% elseif field.className == 'craft\\fields\\Entries' %}

            {% set sources = [] %}

            {# Start our `entries` query #}
            {% set entries = craft.entries %}

            {# Iterate over sources #}
            {% for source in field.sources %}

                {# If All sources is selected in field definition, skip this #}
                {% if source != '*' %}
                    {# Extract UID from the string #}
                    {% set sectionUid = source | replace({'section:': ''}) %}

                    {# Fetch sectionId from UID and push in `sources` array #}
                    {% set sources = sources | merge([craft.app.sections.getSectionByUid(sectionUid).id]) %}
                {% endif %}
            {% endfor %}

            {# If we have `sources` then add to our query, else, fetch everything #}
            {% set entries = sources ? entries.sectionId(sources) : entries %}
            
                Choose
                {% for entry in entries.all() %}
                    {{ entry.title }}
                {% endfor %}
            
        {% endif %}
    {% endfor %}
{% endfor %}

This will cater for multiple sources as well as All being chosen in your field definition


---

