<p>Your assets variable is defined outside the entries loop so it is still referring to the page entry. If you move it inside the loop it should work as expected.</p>

<pre><code>{% set entries = craft.entries.section('documentLibrary') %}
{% for entry in entries if entry.documentType.contains('Report') %}
    {% for asset in entry.documents %}
       &lt;a href="{{ asset.url }}" type="application/pdf;" class="list-group-item active"&gt;{{ entry.title }}&lt;/a&gt;
    {% endfor %}
{% endfor %}
</code></pre>

<p>Rather than doing this manually however, you might also have a look at the <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow">group</a> filter, which can group the entries array by document type.</p>

<pre><code>{% set entries = craft.entries.section('documentLibrary').find() %}
{% set groupedEntries = entries|group('documentType') %}

{% for type, entriesByType in groupedEntries %}
    &lt;h2&gt;{{ type }}&lt;/h2&gt;
    &lt;ul&gt;
        {% for entry in entriesByType %}
            {% for asset in entry.documents %}
                &lt;a href="{{ asset.url }}" type="application/pdf;" class="list-group-item active"&gt;{{ entry.title }}&lt;/a&gt;
            {% endfor %}
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}
</code></pre>

<p>Note: Also if each 'document' only contain one and only one 'asset' (i.e. pdf), then you can also get rid of the asset loop and just use <code>{{ entry.document.first.url }}</code>.</p>

CC BY-SA 3.0
2015-04-28T16:04:41.683Z
2015-04-28T16:04:41.683Z
Douglas McDonald
<p>I'm trying to list entries in a section which are documents. Those documents are grouped by checkbox. I'd like to list the document title and the asset in the entry's url. I only want to list assets which have a specific checkbox ticket. </p>

<p>I was able to output and group the assets by checkbox, but I'm struggling to find that entries asset url. Any thoughts?</p>

<p>This is what I have so far:</p>

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

{# get all checkbox options #}
{% set options = entries.first().documentType.options %}
{% set assets = entry.documents %}

 {% for entry in entries if entry.documentType.contains('Report') %}
    {% for asset in assets %}
       &lt;a href="{{ asset.url }}" type="application/pdf;" class="list-group-item active"&gt;{{ entry.title }}&lt;/a&gt;
    {% endfor %}
 {% endfor %}
</code></pre>

<p>Unfortunately as expected the <code>{{ asset.url }}</code> returns the url of the entry and not of the asset documents which is attached to the entry.</p>

<entries><assets><checkboxes>
List entries of documents in a section grouped by checkbox
# List entries of documents in a section grouped by checkbox

(Asked by: username_0 on 2015-04-28)

I'm trying to list entries in a section which are documents. Those documents are grouped by checkbox. I'd like to list the document title and the asset in the entry's url. I only want to list assets which have a specific checkbox ticket. 
I was able to output and group the assets by checkbox, but I'm struggling to find that entries asset url. Any thoughts?
This is what I have so far:
{% set entries = craft.entries.section('documentLibrary')%}

{# get all checkbox options #}
{% set options = entries.first().documentType.options %}
{% set assets = entry.documents %}

 {% for entry in entries if entry.documentType.contains('Report') %}
    {% for asset in assets %}
       {{ entry.title }}
    {% endfor %}
 {% endfor %}

Unfortunately as expected the {{ asset.url }} returns the url of the entry and not of the asset documents which is attached to the entry.

**Tags:** entries, assets, checkboxes

---

## 1 answers

### Answer by username_1 on 2015-04-28. Score: 1 | Accepted answer

Your assets variable is defined outside the entries loop so it is still referring to the page entry. If you move it inside the loop it should work as expected.
{% set entries = craft.entries.section('documentLibrary') %}
{% for entry in entries if entry.documentType.contains('Report') %}
    {% for asset in entry.documents %}
       {{ entry.title }}
    {% endfor %}
{% endfor %}

Rather than doing this manually however, you might also have a look at the group filter, which can group the entries array by document type.
{% set entries = craft.entries.section('documentLibrary').find() %}
{% set groupedEntries = entries|group('documentType') %}

{% for type, entriesByType in groupedEntries %}
    {{ type }}
    
        {% for entry in entriesByType %}
            {% for asset in entry.documents %}
                {{ entry.title }}
            {% endfor %}
        {% endfor %}
    
{% endfor %}

Note: Also if each 'document' only contain one and only one 'asset' (i.e. pdf), then you can also get rid of the asset loop and just use {{ entry.document.first.url }}.


---

