<p>In Craft/Twig, you'll never need to nest <code>{{</code> and <code>{%</code> tags inside of each other.</p>

<p>So:</p>

<pre><code>{% for sub_entry in craft.entries('{{ entry.sectionName }}').find() %}
</code></pre>

<p>Should be:</p>

<pre><code>{% for sub_entry in craft.entries(entry.sectionName).find() %}
</code></pre>

CC BY-SA 3.0
2016-11-07T19:12:13.383Z
2016-11-07T19:12:13.383Z
Brad Bell
<p>hmm, wat do you mean with sub_entries? As a general pointer I would do it like this: </p>

<pre><code>{% set books = craft.entries.section('books') %} 
</code></pre>

<p>and then loop over the books. </p>

<p>To get back to your question, I would suggest moving all the different sections into 1 channel with multiple types in it. For example:</p>

<p>Channel: Media</p>

<p>Types: </p>

<ul>
<li>Books</li>
<li>Games</li>
<li>Movies</li>
</ul>

<p>Then you can query them like this: </p>

<pre><code>{% set books = craft.entries.section('media').type(['books']) %}

{% for entry in books %}
    &lt;h2&gt;{{entry.title}}&lt;/h2&gt;
{% endfor %}
</code></pre>

<p>More info on types <a href="https://craftcms.com/docs/sections-and-entries#entry-types" rel="nofollow noreferrer">here</a></p>

CC BY-SA 3.0
2016-11-07T17:58:29.700Z
2016-11-07T17:58:29.700Z
Jan_dh
<p>I am new to Craft CMS and although it is quite simple to use I am stuck on this one. I have 3 sections ('books', 'games', 'movies') and want to do the following:</p>

<pre><code>{% for sub_entry in craft.entries('{{ entry.sectionName }}').find() %}
</code></pre>

<p>The problem is that it gives me all sub_entries not just the ones within a specific section i.e. <code>entry.sectionName</code>? If I print out <code>{{ entry.sectionName }}</code> on my website it gives me the correct sectionNames but somehow I can not pass it on to the for loop?</p>

<p>How do I solve this?
Kind regards,
Pete</p>

<templating><entries>
Database Request with entry variable as argument
# Database Request with entry variable as argument

(Asked by: username_0 on 2016-11-07)

I am new to Craft CMS and although it is quite simple to use I am stuck on this one. I have 3 sections ('books', 'games', 'movies') and want to do the following:
{% for sub_entry in craft.entries('{{ entry.sectionName }}').find() %}

The problem is that it gives me all sub_entries not just the ones within a specific section i.e. entry.sectionName? If I print out {{ entry.sectionName }} on my website it gives me the correct sectionNames but somehow I can not pass it on to the for loop?
How do I solve this?
Kind regards,
username_0

**Tags:** templating, entries


---

## 2 answers

### Answer by username_1 on 2016-11-07. Score: 0 | Accepted answer

In Craft/Twig, you'll never need to nest {{ and {% tags inside of each other.
So:
{% for sub_entry in craft.entries('{{ entry.sectionName }}').find() %}

Should be:
{% for sub_entry in craft.entries(entry.sectionName).find() %}


---

### Answer by username_2 on 2016-11-07. Score: 1

hmm, wat do you mean with sub_entries? As a general pointer I would do it like this: 
{% set books = craft.entries.section('books') %} 

and then loop over the books. 
To get back to your question, I would suggest moving all the different sections into 1 channel with multiple types in it. For example:
Channel: Media
Types: 

Books
Games
Movies

Then you can query them like this: 
{% set books = craft.entries.section('media').type(['books']) %}

{% for entry in books %}
    {{entry.title}}
{% endfor %}

More info on types here


---

