<p>The second example won't work since <code>.find()</code> should be at the end of the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a>. But since you treat the CriteriaModel like an array, you don't <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#outputting-elements" rel="nofollow">need to add it at all</a>. </p>

<p>Your first code looks correct, but you should <a href="http://twig.sensiolabs.org/doc/tags/for.html#the-else-clause" rel="nofollow">check if the loop found an entry</a>:</p>

<pre class="lang-twig prettyprint-override"><code>{% for item in craft.entries.section('images').slug('home') %}
    ....
{% else %}
    No entry found
{% endfor %}
</code></pre>

<p>Also your current code is only outputting the title of the <a href="http://buildwithcraft.com/docs/templating/assetfilemodel" rel="nofollow">AssetFileModel</a>:</p>

<blockquote>
  <p>Outputting an AssetFileModel object without attaching a property or
  method will return the asset’s Title</p>
</blockquote>

<p>That's why you should add the "url" property, and also check whether the field contains an asset:</p>

<pre class="lang-twig prettyprint-override"><code>{% for item in craft.entries.section('images').slug('home') %}
    {% set asset = item.image.first() %}

    {% if asset %}
       {{ asset.url }}
    {% else %}
        No asset added to the field
    {% endif %}
{% else %}
    No entry found
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-07-12T14:05:45.370Z
2014-07-12T14:20:55.360Z
2014-07-12T14:20:55.360Z
Victor
<p>Is there any way to output the content of a channel entry by their slug?</p>

<p>For example, say I have an asset field called "image" in each channel entry, I want to output the content of that field only for the channel entry filtered by the slug "home", I've tried both:</p>

<pre><code>{% for item in craft.entries.section('images').slug('home') %}
    {{ item.image.first() }}
{% endfor %}
</code></pre>

<p>and</p>

<pre><code>{% for item in craft.entries.section('images').find().slug('home') %}
    {{ item.image.first() }}
{% endfor %}
</code></pre>

<p>but neither work...</p>

CC BY-SA 3.0
2014-07-12T13:27:11.147Z
By "images" do you mean entries or asset-fields inside entries? Also your code looks correct, can you post a bit more of it?
Victor
CC BY-SA 3.0
2014-07-12T13:49:51.253Z
Hi Victor, I've edited the question to clarify what I mean. In short, say I have an asset field called "image" in each channel entry, I want to output the content of that field *only* for the channel entry filtered by the slug.
bravokiloecho
<templating><entries><sections>
Filter channel entries by slug
# Filter channel entries by slug

(Asked by: username_0 on 2014-07-12)

Is there any way to output the content of a channel entry by their slug?
For example, say I have an asset field called "image" in each channel entry, I want to output the content of that field only for the channel entry filtered by the slug "home", I've tried both:
{% for item in craft.entries.section('images').slug('home') %}
    {{ item.image.first() }}
{% endfor %}

and
{% for item in craft.entries.section('images').find().slug('home') %}
    {{ item.image.first() }}
{% endfor %}

but neither work...

**Tags:** templating, entries, sections
> **Comments:**
> **username_1**: By "images" do you mean entries or asset-fields inside entries? Also your code looks correct, can you post a bit more of it?  
> **username_0**: Hi Victor, I've edited the question to clarify what I mean. In short, say I have an asset field called "image" in each channel entry, I want to output the content of that field *only* for the channel entry filtered by the slug.  

---

## 1 answers

### Answer by username_1 on 2014-07-12. Score: 3 | Accepted answer

The second example won't work since .find() should be at the end of the ElementCriteriaModel. But since you treat the CriteriaModel like an array, you don't need to add it at all. 
Your first code looks correct, but you should check if the loop found an entry:
{% for item in craft.entries.section('images').slug('home') %}
    ....
{% else %}
    No entry found
{% endfor %}

Also your current code is only outputting the title of the AssetFileModel:

Outputting an AssetFileModel object without attaching a property or
  method will return the asset’s Title

That's why you should add the "url" property, and also check whether the field contains an asset:
{% for item in craft.entries.section('images').slug('home') %}
    {% set asset = item.image.first() %}

    {% if asset %}
       {{ asset.url }}
    {% else %}
        No asset added to the field
    {% endif %}
{% else %}
    No entry found
{% endfor %}


---

