Answers.Body: <p><code>seo.twittercard</code> is an <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="noreferrer">ElementCriteriaModel</a>. To access the actual asset, you need to use <code>seo.twittercard.first</code> (or equivalently: <code>seo.twittercard.first()</code>).</p>
  
  <p>However, you should always check that this exists before referencing it:</p>
  
  <pre><code>{% if seo.twittercard|length %}
    &lt;meta(name='twitter:image:', content='{{ seo.twittercard.first.getUrl() }}')&gt;
  {% endif %}
  </code></pre>
  
  <p>And yes, this is a fine way to store images used globally across the site.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T18:30:54.857Z
Answers.Text: What is the benefit of doing the check ( if the image exists?). I am hoping to simplify the code by doing something like this ?    meta(name='twitter:image:src', content='{{ image.getUrl('seo.twittercard.first') }}')
Answers.UserDisplayName: user2022284
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T18:49:01.150Z
Answers.Text: The image might not exist. It might not have been initialized, or the asset might have been removed. And then your site will be mysteriously broken. I think it is always worth checking.
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T18:53:18.190Z
Answers.Text: Thx. Will do then. However, I tried to see if i can simply output the url on the template ( before putting it in the wrapper to check if it exists ). this is not working:   {{ image.getUrl('seo.twittercard.first') }}')
Answers.UserDisplayName: user2022284
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T19:00:29.410Z
Answers.Text: oops! fixing my answer. You want `{{seo.twittercard.first.getUrl()}}`
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-15T03:13:08.817Z
Answers.Text: boom! works nicely! Thx.
Answers.UserDisplayName: user2022284
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T18:25:02.180Z
Answers.LastActivityDate: 2015-08-14T19:02:02.820Z
Answers.LastEditDate: 2015-08-14T19:02:02.820Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>This is a general structure to display global images in any template:</p>
  <pre><code>&lt;img src=&quot;{{ globalHandle.globalAssetHandle.one().getUrl }}&quot; alt=&quot;&quot;&gt;
  </code></pre>
  <p>You have to set your global handle here:</p>
  <p><a href="https://i.sstatic.net/NFDwS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NFDwS.png" alt="enter image description here" /></a></p>
  <p>And your global asset handle here:</p>
  <p><a href="https://i.sstatic.net/iDFYU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iDFYU.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-15T21:14:26.277Z
Answers.LastActivityDate: 2020-12-15T21:14:26.277Z
Answers.UserDisplayName: Alexis Dalai Waldo Jiménez
Body: <p>I have setup a global set for images i use across the site. I have one for seo - where I have images for a twitter card and Facebook image in my seo settings. There is only one image for each field ( so hoping to avoid using the array syntax )</p>
  
  <p>Two questions:</p>
  
  <ol>
  <li><p>I am not sure how to access the images uploaded into this global variable. My global set has a handle "seo" and the image's handle is "twittercard". This isn't working :</p>
  
  <p>meta(name='twitter:image:', content='{{ image.getUrl('seo.twittercard') }}')</p></li>
  <li><p>Is this the most efficient way to store images used globally across the site? ( via global image variables?)</p></li>
  </ol>
  
Tags: <templating><assets><image><globals>
Title: Global Image Variables?
ThreadText: # Global Image Variables?
  
  (Asked by: username_0 on 2015-08-14)
  
  I have setup a global set for images i use across the site. I have one for seo - where I have images for a twitter card and Facebook image in my seo settings. There is only one image for each field ( so hoping to avoid using the array syntax )
  
  Two questions:
  
  1. I am not sure how to access the images uploaded into this global variable. My global set has a handle "seo" and the image's handle is "twittercard". This isn't working :
  
     meta(name='twitter:image:', content='{{ image.getUrl('seo.twittercard') }}')
  2. Is this the most efficient way to store images used globally across the site? ( via global image variables?)
  
  **Tags:** templating, assets, image, globals
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-08-14. Score: 5 | Accepted answer
  
  `seo.twittercard` is an [ElementCriteriaModel](http://buildwithcraft.com/docs/templating/elementcriteriamodel). To access the actual asset, you need to use `seo.twittercard.first` (or equivalently: `seo.twittercard.first()`).
  
  However, you should always check that this exists before referencing it:
  
  ```
  {% if seo.twittercard|length %}
    <meta(name='twitter:image:', content='{{ seo.twittercard.first.getUrl() }}')>
  {% endif %}
  
  ```
  
  And yes, this is a fine way to store images used globally across the site.
  
  > **Comments:**
  > **username_0**: What is the benefit of doing the check ( if the image exists?). I am hoping to simplify the code by doing something like this ?    meta(name='twitter:image:src', content='{{ image.getUrl('seo.twittercard.first') }}')  
  > **username_1**: The image might not exist. It might not have been initialized, or the asset might have been removed. And then your site will be mysteriously broken. I think it is always worth checking.  
  > **username_0**: Thx. Will do then. However, I tried to see if i can simply output the url on the template ( before putting it in the wrapper to check if it exists ). this is not working:   {{ image.getUrl('seo.twittercard.first') }}')  
  > **username_1**: oops! fixing my answer. You want `{{seo.twittercard.first.getUrl()}}`  
  > **username_0**: boom! works nicely! Thx.  
  
  ---
  
  ### Answer by username_2 on 2020-12-15. Score: 3
  
  This is a general structure to display global images in any template:
  
  ```
  <img src="{{ globalHandle.globalAssetHandle.one().getUrl }}" alt="">
  
  ```
  
  You have to set your global handle here:
  
  [![enter image description here](https://i.sstatic.net/NFDwS.png)](https://i.sstatic.net/NFDwS.png)
  
  And your global asset handle here:
  
  [![enter image description here](https://i.sstatic.net/iDFYU.png)](https://i.sstatic.net/iDFYU.png)
  
  
  ---
  
  