<p>Assets fields always return <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel’s</a> in templates. To get the actual related asset, do this:</p>

<pre><code>{% set asset = work.mediakit.first() %}
</code></pre>

<p>You can’t be <em>sure</em> that there’s actually a related asset, so it’s worth making sure <code>work.mediakit.first()</code> actually returned something before accessing its properties:</p>

<pre><code>{% if asset %}
    {{ asset.url }}
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-10-13T13:27:41.343Z
"Asset fields are always returned as arrays in templates" - I think you just helped me level up (now at level 2!)  Thanks a ton.
Rockwell Rice
CC BY-SA 3.0
2015-10-13T18:02:46.120Z
...and because they are arrays, you can test if the field actually contains any images or not like this: ```{% if work.mediakit|length %}```
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-10-16T07:00:10.840Z
Technically they return [ElementCriteriaModel’s](http://buildwithcraft.com/docs/templating/elementcriteriamodel), not arrays, and grabbing the first asset with `[0]` could potentially be excessive if you have more than one asset and only need the first one (as this will actually load _all_ of the assets behind the scenes, before returning the first one).
Brandon Kelly
CC BY-SA 3.0
2015-10-13T13:25:14.173Z
2015-10-16T06:55:47.433Z
2015-10-16T06:55:47.433Z
Aaron Berkowitz
<p>I can't, for the life of me, find an answer to this question.</p>

<p>I have a global called <strong>work</strong>.  It has three Asset fields.  One is called <strong>mediakit</strong>, which is an upload of a PDF.  I am trying to get the file name of that asset and add it into the template but cannot find anything giving me the proper way to do this in the template</p>

<p>Based on the documentation I thought:</p>

<pre><code> {{ work.mediakit }}
</code></pre>

<p>would output something at least but nothing shows and so whittling away from there to get it to call the correct path has eluded me.</p>

<p>Can anyone give me the correct way to call that?</p>

<p>The path is:   </p>

<pre><code>  "/assets/medikit/{{ the filename of the pdf uploaded}}"
</code></pre>

<globals>
Calling an Asset field from a Global
# Calling an Asset field from a Global

(Asked by: username_0 on 2015-10-13)

I can't, for the life of me, find an answer to this question.
I have a global called work.  It has three Asset fields.  One is called mediakit, which is an upload of a PDF.  I am trying to get the file name of that asset and add it into the template but cannot find anything giving me the proper way to do this in the template
Based on the documentation I thought:
 {{ work.mediakit }}

would output something at least but nothing shows and so whittling away from there to get it to call the correct path has eluded me.
Can anyone give me the correct way to call that?
The path is:   
  "/assets/medikit/{{ the filename of the pdf uploaded}}"

**Tags:** globals


---

## 1 answers

### Answer by username_1 on 2015-10-13. Score: 3 | Accepted answer

Assets fields always return ElementCriteriaModel’s in templates. To get the actual related asset, do this:
{% set asset = work.mediakit.first() %}

You can’t be sure that there’s actually a related asset, so it’s worth making sure work.mediakit.first() actually returned something before accessing its properties:
{% if asset %}
    {{ asset.url }}
{% endif %}

> **Comments:**
> **username_0**: "Asset fields are always returned as arrays in templates" - I think you just helped me level up (now at level 2!)  Thanks a ton.  
> **username_2**: ...and because they are arrays, you can test if the field actually contains any images or not like this: ```{% if work.mediakit|length %}```  
> **username_3**: Technically they return [ElementCriteriaModel’s](http://buildwithcraft.com/docs/templating/elementcriteriamodel), not arrays, and grabbing the first asset with `[0]` could potentially be excessive if you have more than one asset and only need the first one (as this will actually load _all_ of the assets behind the scenes, before returning the first one).  

---

