smarty icon indicating copy to clipboard operation
smarty copied to clipboard

getTemplateVars not working for in template defined variables

Open blaaat opened this issue 1 year ago • 3 comments

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

blaaat avatar Apr 11 '24 12:04 blaaat

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

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

wisskid avatar Apr 12 '24 08:04 wisskid

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.

blaaat avatar Apr 12 '24 08:04 blaaat

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.

wisskid avatar Apr 12 '24 09:04 wisskid