Page 1 of 1

Including templates within templates - assigning variables

Posted: Tue May 03, 2016 2:41 pm
by spcherub
I'm trying to learn the new mechanism that allows the inclusion of one template inside another. Here's what I have so far:

Template SubA consists of the following code:

Code: Select all

{content block="sub_a" label="sub_a" assign="sub_a"}
Template Main consists of the following code (simplified):

Code: Select all

{include file="cms_template:SubA}
{content}
{$sub_a}
I am not able to view the value of the variable $sub_a within the page that uses Main as a template - value is blank. What is the way to assign the content in one template to a variable that can be used in another after inclusion?

TIA
Sanjay

Re: Including templates within templates - assigning variabl

Posted: Tue May 03, 2016 2:51 pm
by Rolf

Re: Including templates within templates - assigning variabl

Posted: Tue May 03, 2016 4:17 pm
by spcherub
@Rolf - thanks for the reference to global scope - very useful!

However, I tried the following (CMSMS v2.1.3) and still no dice:
Template SubA consists of the following code:

Code: Select all

{content block="sub_a" label="sub_a" assign="sub_a" scope=global}
Template Main consists of the following code (simplified):

Code: Select all

{include file="cms_template:SubA}
{content}
{$sub_a}
I'm still not seeing the content from the variable $sub_a even after declaring it global in scope.

What am I missing?

Thanks,
Sanjay

Re: Including templates within templates - assigning variabl

Posted: Tue May 03, 2016 4:23 pm
by Jo Morg
At this point we can only alter variable scopes on variables declarations only. So:

Code: Select all

{content block="sub_a" label="sub_a" assign="sub_a" scope=global}
won't work...

Code: Select all

{$sub_a="{content block='sub_a' label='sub_a'}" scope=global}
The above should work fine though.

Re: Including templates within templates - assigning variabl

Posted: Tue May 03, 2016 4:33 pm
by spcherub
@Jo Morg - Thanks that fixed my problem.