Content block with scope global is not populating

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
rbaby
Forum Members
Forum Members
Posts: 144
Joined: Thu Feb 07, 2008 10:28 pm

Content block with scope global is not populating

Post 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?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Content block with scope global is not populating

Post 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}
rbaby
Forum Members
Forum Members
Posts: 144
Joined: Thu Feb 07, 2008 10:28 pm

Re: Content block with scope global is not populating

Post 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}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Content block with scope global is not populating

Post 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
Post Reply

Return to “CMSMS Core”