Page 1 of 1

what works and doesn't with smarty scopes

Posted: Mon Sep 05, 2016 5:01 pm
by dlen
Hi,

i write this down to try to help others with the same problem.

Situation: Assigned values to smarty variables in template file above the <__html> tag. Used always the attribute "scope=global".

Some variables could be used from down below the </__body> tag, while others couldn't.

Turned out, that

Code: Select all

{varname = some_value scope=global}
{assign name='varname' value=some_value scope=global}
worked, while

Code: Select all

{some_smarty_tag assign='varname' scope=global}
didn't.

Any constructive remark welcome...

Re: what works and doesn't with smarty scopes

Posted: Mon Sep 05, 2016 5:20 pm
by Jo Morg
dlen wrote: Turned out, that

Code: Select all

{varname = some_value scope=global}
{assign name='varname' value=some_value scope=global}
worked, while

Code: Select all

{some_smarty_tag assign='varname' scope=global}
didn't.
Modules, plugins and UDT's currently don't have a way to recognize the scope parameter, as it only applies to variables. The best way to go around this limitation is:

Code: Select all

{$var="{some_smarty_tag}" scope=global}
Please note that in this case we use the double quotes to make sure whatever we are assigning to the var is evaluated beforehand. On all other situations the best practice is to use single quotes.
Additionally use this article as reference: http://www.cmscanbesimple.org/blog/smar ... e-examples

Re: what works and doesn't with smarty scopes

Posted: Mon Sep 05, 2016 10:25 pm
by dlen
thanks for the valuable link.