<p>I'm trying to send a meta-data image from an entry template to the main layout template.  The image is in a matrix block on the entry.  It comes out correctly when I call it on the entry page, but when I try to pass it to the layout it doesn't see it and reverts to the default image called in the layout.  Any help is appreciated</p>

<p>_Layout template</p>

<pre><code>&lt;meta property="twitter:image:src" content={% if twitterpic is defined %}"{{ twitterpic }}"{%else%}"{{ siteImage.getUrl('twitterPic') }}" {%endif%}/&gt;
</code></pre>

<p>_entry template</p>

<pre><code>{#  social image  #}
{% for block in entry.projectImage%}
{% set image for block.projectImage.first() %}
{% set twitterpic =image.getUrl('twitterPic') %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-07-14T15:48:04.393Z
This seems like a duplicate of: http://craftcms.stackexchange.com/q/153/177
Victor
CC BY-SA 3.0
2014-07-14T16:07:30.603Z
Hi @Micah, and welcome to the Craft CMS Stack Exchange site! As Victor In pointed out, a similar question has already been asked and answered here. You might also find [this question](http://craftcms.stackexchange.com/questions/859/how-do-i-add-an-html-block-from-template-extension-to-main-layout-template-i-e/860#860) on passing meta tags useful.
Matt Stein
CC BY-SA 3.0
2014-07-14T16:47:10.023Z
I'm in the same block, and all my other variables are passing fine.  That's not the problem.  The problem seems to be specific to the asset call
Micah Morgan
CC BY-SA 3.0
2014-07-14T17:13:24.873Z
@MicahMorgan As the linked answer indicates, this is a scope issue. You're defining `twitterpic` within your foor loop, but you first need to define it *outside the loop* if you want it to be available elsewhere. You're also running `.getUrl('twitterPic')` twice. You should either pass the asset (`image`) or pass the URL reference (`twitterpic`).
Matt Stein
CC BY-SA 3.0
2014-07-14T18:21:19.817Z
thank you for the clarification.  I read it all, but it didn't sink in
Micah Morgan
CC BY-SA 3.0
2014-07-14T20:26:36.670Z
@MicahMorgan "I read it all, but it didn't sink in" explains most of the problems I have :)
Matt Stein
<templating>
How do I pass an image to the _layout
# How do I pass an image to the _layout

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

I'm trying to send a meta-data image from an entry template to the main layout template.  The image is in a matrix block on the entry.  It comes out correctly when I call it on the entry page, but when I try to pass it to the layout it doesn't see it and reverts to the default image called in the layout.  Any help is appreciated
_Layout template


_entry template
{#  social image  #}
{% for block in entry.projectImage%}
{% set image for block.projectImage.first() %}
{% set twitterpic =image.getUrl('twitterPic') %}
{% endfor %}

**Tags:** templating

> **Comments:**
> **username_1**: This seems like a duplicate of: http://craftcms.stackexchange.com/q/153/177  
> **username_2**: Hi @Micah, and welcome to the Craft CMS Stack Exchange site! As username_1 In pointed out, a similar question has already been asked and answered here. You might also find [this question](http://craftcms.stackexchange.com/questions/859/how-do-i-add-an-html-block-from-template-extension-to-main-layout-template-i-e/860#860) on passing meta tags useful.  
> **username_0**: I'm in the same block, and all my other variables are passing fine.  That's not the problem.  The problem seems to be specific to the asset call  
> **username_2**: @MicahMorgan As the linked answer indicates, this is a scope issue. You're defining `twitterpic` within your foor loop, but you first need to define it *outside the loop* if you want it to be available elsewhere. You're also running `.getUrl('twitterPic')` twice. You should either pass the asset (`image`) or pass the URL reference (`twitterpic`).  
> **username_0**: thank you for the clarification.  I read it all, but it didn't sink in  
> **username_2**: @MicahMorgan "I read it all, but it didn't sink in" explains most of the problems I have :)  

---

## 0 answers

