|
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 |
omstefanov Smarty n00b
Joined: 15 Apr 2010 Posts: 1
|
Posted: Thu Apr 15, 2010 7:59 pm Post subject: How to retain content of variable between calls |
|
|
Hi,
I'm trying to add some logic in a rather complex application consisting of php with smarty templates. To do so I need to be able to store the value of a variable that is only known at the time a smarty tpl is executed, and then be able to query this value on a future execution.
I've tried, in the php to define the variable as global:
Code: | global $prev_value; |
Then, in the tpl, to query this variable by:
Code: | {if $prev_value != $f_45}
... do something
{/if} |
and then, at the end of the tpl to save the value, by:
Code: | {assign var='prev_sort_value' value=$f_45} |
or, when this didn't seem to work, by:
Code: | {php}
assign(var='prev_value' value=$f_45);
{/php} |
Whenever I display {prev_value} at the end, I see a value, but by the next time the value is empty again.
I even tried to add a "define global" at the start of the tpl. I'm not sure if this is the right way:
Code: | {php}
global $prev_value;
{/php} |
Can anyone tell me how to fix this, or show a better way? There must be a way to change a value of a variable (defined elsewhere) within a smarty tpl and have this value persist. Or?
Kind regards,
omstefanov[/code] |
|
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
|