|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Terry151151 Smarty Regular
Joined: 06 May 2010 Posts: 37 Location: Sydney Australia
|
Posted: Wed Apr 09, 2014 10:28 am Post subject: Variable one behind using "include" several times |
|
|
I have a template that includes another template several times.
The included template uses a template function to set up variables.
The problem is that the variables are always one behind.
Example Structure:
The included template (TheTemplate.tpl) has the structure:
{SETUP_FUNCTION}
{$VARIABLE}
In the SETUP_FUNCTION I do:
$smarty->assign( 'VARIABLE', ++$this->Count );
The calling template does:
{include 'TheTemplate.tpl'}
{include 'TheTemplate.tpl'}
{include 'TheTemplate.tpl'}
{include 'TheTemplate.tpl'}
$VARIABLE displays as:
'blank'
1
2
3
where as $VARIABLE should displays as:
1
2
3
4
Does any body know why and/or know a solution?
Thanks in advance.
Terry |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 09, 2014 4:01 pm Post subject: |
|
|
In the template function you should use the template object passed as second parameter to assign the variable
Code: | $template->assign( 'VARIABLE', ++$this->Count ); |
|
|
Back to top |
|
Terry151151 Smarty Regular
Joined: 06 May 2010 Posts: 37 Location: Sydney Australia
|
Posted: Wed Apr 09, 2014 8:37 pm Post subject: |
|
|
I didn't know that there was a $template->assign.
I knew that there was a $template->smarty->assign but this did had the same problem.
How come this makes a difference as I thought that the $smarty->assign was supposed to be global?
Regards
Terry |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 09, 2014 8:43 pm Post subject: |
|
|
When a template is activated a local template scope is generated. The template works with this scope to isolate it's modifications from the outside world. All Smarty methods and properties can be accessed by the template object in plugins. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|