Including templates within templates - assigning variables

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.
Locked
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Including templates within templates - assigning variables

Post 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
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Including templates within templates - assigning variabl

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: Including templates within templates - assigning variabl

Post 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
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Including templates within templates - assigning variabl

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: Including templates within templates - assigning variabl

Post by spcherub »

@Jo Morg - Thanks that fixed my problem.
Locked

Return to “CMSMS Core”