phpsmartysmarty3smarty2

Smarty upgrade 2 to 3 _tag_stack options


I am upgrading some code from smarty 2 to 3. There is a value in the smarty object called _tag_stack which seems to return an array of tag values. What is a 1 to 1 replacement for this in Smarty 3? I am looking at getTags() but I am unsure it returns the same values.

The code I am looking at is:


if($section_name == '' && $smarty->_tag_stack[0][0] == 'bp_section'){ $section_name = $smarty->_tag_stack[0][1]['name']; }



Solution

  • Smarty 3 is a pretty radical rewrite, Smarty 2 was from the days before property visibility was a thing in PHP, and the tag stack was actually supposed to be a private property of the Smarty class, and within Smarty 2, the only class that referenced it was the compiler (Smarty_Compiler), which actually extends the Smarty class. So while it's possible to access the tag stack in Smarty 2 from external code, is was never intended.

    In Smarty 3, the compiler no longer extends the Smarty class, it extends Smarty_Internal_TemplateCompilerBase, which is where the _tag_stack property lives. It's a public property, despite the underscore. Smelly.

    Smarty_Internal_Template has a $compiler property, so that's probably your best bet if you're trying to access the tag stack inside a custom function.

    The getTags method returns all of the tags and their arguments used in a template, it's not something that's updated in real time like the tag stack.