Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-12T14:05:45.370Z
Answers.LastActivityDate: 2014-07-12T14:20:55.360Z
Answers.LastEditDate: 2014-07-12T14:20:55.360Z
Answers.UserDisplayName: Victor
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-12T13:27:11.147Z
Comments.Text: By "images" do you mean entries or asset-fields inside entries? Also your code looks correct, can you post a bit more of it?
Comments.UserDisplayName: Victor
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-12T13:49:51.253Z
Comments.Text: 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.
Comments.UserDisplayName: bravokiloecho
Tags: <templating><entries><sections>
Title: Filter channel entries by slug
ThreadText: # 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 username_1, 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](http://buildwithcraft.com/docs/templating/elementcriteriamodel). But since you treat the CriteriaModel like an array, you don't [need to add it at all](http://buildwithcraft.com/docs/templating/elementcriteriamodel#outputting-elements).
  
  Your first code looks correct, but you should [check if the loop found an entry](http://twig.sensiolabs.org/doc/tags/for.html#the-else-clause):
  
  ```twig
  {% 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](http://buildwithcraft.com/docs/templating/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:
  
  ```twig
  {% 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 %}
  
  ```
  
  
  ---
  
  