Page 1 of 1

Content block with scope global is not populating

Posted: Fri Mar 08, 2019 11:46 pm
by rbaby
Hi guys,

In my content template, I have the following defined:

{content_image block='hero_image' label='Hero Image' urlonly='1' exclude='thumb_' dir='images/parallax' assign='hero' scope=global}

In my head include file I have:

<meta property="og:image" content="{$hero|default:'/uploads/images/social_logo.png'}" />

It keeps showing the default, regardless. I have CGBlog and I have:
{if $entry->fieldsbyname.870x300}
{$hero="{$entry->file_location}/{$entry->fieldsbyname.870x300->value}" scope=global}
{/if}

That seems to work fine, but it doesn't work on my regular content pages. What did I miss?

Re: Content block with scope global is not populating

Posted: Sat Mar 09, 2019 11:41 am
by velden
scope is a parameter of {assign}, not of all smarty tags.

Try:

Code: Select all

{content_image block='hero_image' label='Hero Image' urlonly='1' exclude='thumb_' dir='images/parallax' assign='hero'}
{$hero=$hero scope=global}

Re: Content block with scope global is not populating

Posted: Sun Mar 10, 2019 5:36 am
by rbaby
velden wrote:scope is a parameter of {assign}, not of all smarty tags.

Try:

Code: Select all

{content_image block='hero_image' label='Hero Image' urlonly='1' exclude='thumb_' dir='images/parallax' assign='hero'}
{$hero=$hero scope=global}
Thank you velden, I placed it right underneath in my content template and it's still loading default. I tried this the other night after finding a blog sample, not sure what could be wrong. Does it matter that my <head> </head> code is in a different template...?

{content_image block='hero_image' label='Hero Image' urlonly='1' exclude='thumb_' dir='images/parallax' assign='hero'}
{$hero=$hero scope=global}

Re: Content block with scope global is not populating

Posted: Sun Mar 10, 2019 10:35 am
by velden
Does it matter that my <head> </head> code is in a different template...?
It sure can matter. It should be noted that CMSMS processes and scopes variables based on three areas in the template. The </__body> and <head> tags are essential for that to work.

https://cmscanbesimple.org/blog/base-cm ... d-metatags

https://docs.cmsmadesimple.org/configur ... processing

It's good practice to process the content blocks at the top of your page template, assign the output to a variable and give that variable a global scope.

Code: Select all

{content assign=main_content}{$main_content=$main_content scope=global}
<__html>
  <head></head>
  </__body>
   {$main_content}
  <__body>
</__html>
You can (should) do the same for the hero image. Further, have a look at template inheritance if you're not using it yet.

https://cmscanbesimple.org/blog/the-pow ... gn-manager