<p>You'll want to use <code>block.icon.first()</code> if you just want the first Asset, or you could loop through all Assets:</p>

<pre><code>{% for block in entry.visitorContentBuilder %}

    {% if block.type == "listItemWithIcon" %}

        &lt;ul&gt;
            {% for icon in block.icon %}
                &lt;li&gt;{{ icon }}
            {% endfor %}
        &lt;/ul&gt;

    {% endif %}

{% endfor %}
</code></pre>

<p>See <a href="https://craftcms.stackexchange.com/questions/265/what-are-the-differences-between-an-elementcriteriamodel-and-fetched-elements">here</a> for a description of the difference between an ElementCriteriaModel and actual fetched elements in Craft.</p>

CC BY-SA 3.0
2017-08-02T12:24:14.520Z
Thank you! That solved it for me. Also, in this particular case {{block.icon.first.url}} produced the path that I was actually looking for. I wish there was some sort of "default" output for {{ block.icon }} instead of an error.
Panos Spiliotis
CC BY-SA 3.0
2017-08-01T17:30:27.023Z
2017-08-01T17:30:27.023Z
Brad Bell
<p>I have set up a Matrix field that contains a block type that contains among other things, an asset field. 
Trying to iterate through the contents of that matrix field works just fine for all other field types but produces the following error when it comes across the asset field type.</p>

<blockquote>
  <p>Object of class Craft\ElementCriteriaModel could not be converted to string</p>
</blockquote>

<p>This is the part of the template that produces the error. "icon" is the asset field type.</p>

<pre><code>{% for block in entry.visitorContentBuilder %}

    {% if block.type == "listItemWithIcon" %}

        {{ block.icon }}

    {% endif %}

{% endfor %}
</code></pre>

<assets><matrix><assetfilemodel>
Object of class Craft\ElementCriteriaModel could not be converted to string
# Object of class Craft\ElementCriteriaModel could not be converted to string

(Asked by: username_0 on 2017-08-01)

I have set up a Matrix field that contains a block type that contains among other things, an asset field. 
Trying to iterate through the contents of that matrix field works just fine for all other field types but produces the following error when it comes across the asset field type.

Object of class Craft\ElementCriteriaModel could not be converted to string

This is the part of the template that produces the error. "icon" is the asset field type.
{% for block in entry.visitorContentBuilder %}

    {% if block.type == "listItemWithIcon" %}

        {{ block.icon }}

    {% endif %}

{% endfor %}

**Tags:** assets, matrix, assetfilemodel


---

## 1 answers

### Answer by username_1 on 2017-08-01. Score: 2 | Accepted answer

You'll want to use block.icon.first() if you just want the first Asset, or you could loop through all Assets:
{% for block in entry.visitorContentBuilder %}

    {% if block.type == "listItemWithIcon" %}

        
            {% for icon in block.icon %}
                {{ icon }}
            {% endfor %}
        

    {% endif %}

{% endfor %}

See here for a description of the difference between an ElementCriteriaModel and actual fetched elements in Craft.

> **Comments:**
> **username_0**: Thank you! That solved it for me. Also, in this particular case {{block.icon.first.url}} produced the path that I was actually looking for. I wish there was some sort of "default" output for {{ block.icon }} instead of an error.  

---

