Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Variable one behind using "include" several times

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Terry151151
Smarty Regular


Joined: 06 May 2010
Posts: 37
Location: Sydney Australia

PostPosted: Wed Apr 09, 2014 10:28 am    Post subject: Variable one behind using "include" several times Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Apr 09, 2014 4:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
Terry151151
Smarty Regular


Joined: 06 May 2010
Posts: 37
Location: Sydney Australia

PostPosted: Wed Apr 09, 2014 8:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Apr 09, 2014 8:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP