smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.25k stars 708 forks source link

getTemplateVars not working for in template defined variables #991

Open blaaat opened 5 months ago

blaaat commented 5 months ago

Hi,

In Smarty 4 it was possible to assign a variable inside a template and use this after fetching in code.

{assign var="var" value=$from_name scope="root"}

$smarty->getTemplateVars()

In smarty 5.0.2 this only returns the variables assigned in PHP. Tried to change the (undocumented) scope to global without success

wisskid commented 5 months ago

I can make this work, but only when using the 'global' scope:

{assign var="b" value="x" scope="global"}
$smarty->getTemplateVars('b') // = 'x'
blaaat commented 5 months ago

You're right, I must have made a mistake when testing this yesterday. Thanks :)

So this issue is mostly related to #878 Maybe it would be nice to have this backwards incompatible change documented in the changelog.

wisskid commented 5 months ago

You are right. The change was documented in the changelog as "Template variable scope bubbling has been simplified and made more consistent. The global scope now equals the Smarty scope in order to avoid global state side effects. Please read the documentation for more details." This doesn't really suggest what could go wrong, but I hadn't forseen this either to be honest.