<p>When you call <code>myGlobalSet.myAssetsField</code>, you're creating an <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow"><strong>ElementCriteriaModel</strong></a>. This is significant, because an ElementCriteriaModel is basically a "search object".</p>

<p>Your <code>design.imgs</code> call produces an ElementCriteriaModel based on <a href="http://buildwithcraft.com/docs/templating/craft.assets" rel="nofollow"><strong><code>craft.assets</code></strong></a>. It will return only the assets which are <a href="http://buildwithcraft.com/docs/relations" rel="nofollow">related to</a> your global field.</p>

<p>You can manipulate your ElementCriteriaModel in whatever way you want!</p>

<pre><code>{% set myAsset = design.imgs.kind('image').sourceId(1).first %}
</code></pre>

CC BY-SA 3.0
2015-08-16T11:53:59.370Z
Lindsey - I am looking to output the url for the specific image. not sure how to do that with your example above.
user2022284
CC BY-SA 3.0
2015-08-16T16:05:02.993Z
Quite easily in fact... `myAsset.getUrl()`
Lindsey D
CC BY-SA 3.0
2015-08-16T16:35:28.537Z
@user2022284 - You need some identifiable piece of information about the file you're looking for, like its file name or asset ID, etc. so you can tell Craft what to search for.  Do you know any of those ahead of time?
Brad Bell
CC BY-SA 3.0
2015-08-16T21:49:40.850Z
Hi Brad : I know the image name and title - both of which will be unique across all the images.
user2022284
CC BY-SA 3.0
2015-08-16T21:57:21.317Z
@user2022284: If you know the image's name & title, why not just access it directly through `craft.assets`? There's no need to refer to the global field at all if you already know which asset you want.
Lindsey D
CC BY-SA 3.0
2015-08-16T07:33:31.140Z
2015-08-16T07:33:31.140Z
Lindsey D
<p>If you have a smallish (under a dozen or so), pre-determined set of distinguished images, then I would create a separate global asset for each of them. So you would have <code>design.logo</code>, <code>design.facebookIcon</code>, etc. And then just refer to them that way:</p>

<pre><code>{% if design.logo|length %}
  {{ design.logo.first.getUrl() }}
{% endif %}
</code></pre>

<p>Always check that an asset exists before you use it. Otherwise you will have your site front-end mysteriously crashing at some point in the future when that asset is not there</p>

CC BY-SA 3.0
2015-08-16T21:51:26.833Z
Hi Marion, Yes, this works for the scenario you describe . Perhaps it easier this way. But will like to still learn how to do so if I were to dump everything in one field - with image name and title being the known element , then search for it.
user2022284
CC BY-SA 3.0
2015-08-16T18:31:24.757Z
2015-08-16T18:31:24.757Z
Marion Newlevant
<p>I am using a global set to store image assets used across the site.  I am not sure how to reference a specific image. I know how to get the image if its just one, using :</p>

<pre><code>{{ design.imgs | length ? design.imgs.first().getUrl() : '' }}
</code></pre>

<p>What if there are several images and I am looking for a specific one?</p>

CC BY-SA 3.0
2015-08-16T02:55:23.057Z
You could loop through them. But what distinguishes this specific one?
Marion Newlevant
CC BY-SA 3.0
2015-08-16T03:02:44.840Z
The loop will return all of the images, correct? I am storing a bunch of images in the global and always need to call just one at a time - like the logo.  Each one has a different asset name. ( filename or title )
user2022284
CC BY-SA 3.0
2015-08-16T06:19:29.700Z
The loop will return all of them, one at a time. If you have a fixed set of specific images (logo, ...), I would make a global asset for each one. So `design.logo` would be your one logo image. If you are trying to do something else, please explain.
Marion Newlevant
CC BY-SA 3.0
2015-08-16T11:40:25.423Z
Looks like, when using global sets, you can either make a field for every specific item ( like in your example above - design.logo ) or throw all the assets into one field ( imgs in my case).  Looks like your methodology is far simpler.  Is throwing all items into one field and searching for them with the methodology suggested by Lindsey D below unnecessarily complicated ?
user2022284
CC BY-SA 3.0
2015-08-16T18:22:48.480Z
If you know in advance what all the specific items are, and there aren't more than maybe a dozen of them, then I would say my methodology is simpler. But otherwise you may need to go with searching. And you could throw some together in one field, and make specific fileds for some others.
Marion Newlevant
<templating><assets><image><globals>
Find specific image from global image set?
# Find specific image from global image set?

(Asked by: username_0 on 2015-08-16)

I am using a global set to store image assets used across the site.  I am not sure how to reference a specific image. I know how to get the image if its just one, using :
{{ design.imgs | length ? design.imgs.first().getUrl() : '' }}

What if there are several images and I am looking for a specific one?

**Tags:** templating, assets, image, globals

> **Comments:**
> **username_1**: You could loop through them. But what distinguishes this specific one?  
> **username_0**: The loop will return all of the images, correct? I am storing a bunch of images in the global and always need to call just one at a time - like the logo.  Each one has a different asset name. ( filename or title )  
> **username_1**: The loop will return all of them, one at a time. If you have a fixed set of specific images (logo, ...), I would make a global asset for each one. So `design.logo` would be your one logo image. If you are trying to do something else, please explain.  
> **username_0**: Looks like, when using global sets, you can either make a field for every specific item ( like in your example above - design.logo ) or throw all the assets into one field ( imgs in my case).  Looks like your methodology is far simpler.  Is throwing all items into one field and searching for them with the methodology suggested by username_2 below unnecessarily complicated ?  
> **username_1**: If you know in advance what all the specific items are, and there aren't more than maybe a dozen of them, then I would say my methodology is simpler. But otherwise you may need to go with searching. And you could throw some together in one field, and make specific fileds for some others.  

---

## 2 answers

### Answer by username_2 on 2015-08-16. Score: 1

When you call myGlobalSet.myAssetsField, you're creating an ElementCriteriaModel. This is significant, because an ElementCriteriaModel is basically a "search object".
Your design.imgs call produces an ElementCriteriaModel based on craft.assets. It will return only the assets which are related to your global field.
You can manipulate your ElementCriteriaModel in whatever way you want!
{% set myAsset = design.imgs.kind('image').sourceId(1).first %}

> **Comments:**
> **username_0**: Lindsey - I am looking to output the url for the specific image. not sure how to do that with your example above.  
> **username_2**: Quite easily in fact... `myAsset.getUrl()`  
> **username_3**: @username_0 - You need some identifiable piece of information about the file you're looking for, like its file name or asset ID, etc. so you can tell Craft what to search for.  Do you know any of those ahead of time?  
> **username_0**: Hi Brad : I know the image name and title - both of which will be unique across all the images.  
> **username_2**: @username_0: If you know the image's name & title, why not just access it directly through `craft.assets`? There's no need to refer to the global field at all if you already know which asset you want.  

---

### Answer by username_1 on 2015-08-16. Score: 1

If you have a smallish (under a dozen or so), pre-determined set of distinguished images, then I would create a separate global asset for each of them. So you would have design.logo, design.facebookIcon, etc. And then just refer to them that way:
{% if design.logo|length %}
  {{ design.logo.first.getUrl() }}
{% endif %}

Always check that an asset exists before you use it. Otherwise you will have your site front-end mysteriously crashing at some point in the future when that asset is not there

> **Comments:**
> **username_0**: Hi Marion, Yes, this works for the scenario you describe . Perhaps it easier this way. But will like to still learn how to do so if I were to dump everything in one field - with image name and title being the known element , then search for it.  

---

