Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$smarty.current_dir value when called from extended template

My code is as follows:

content.tpl:

{* Smarty *} 
{extends file='PageContentLayout.tpl'}

PageContentLayout.tpl

{* Smarty *} 
{block name="file_name"}
    <p>{$smarty.current_dir}</p>
    <p>{$smarty.template}</p>
{/block}


{block name="other_content"} 
    ... 
    {* blah... *} 
    ... 
{/block} 

In earlier versions of smarty, this code would print the template name and path of the file: content.tpl.

However, I've just upgraded to 3.1.29, and it now seems that it's the name of the base file PageContentLayout.tpl that is being printed.

I assume that this is a deliberate design change in different versions of Smarty, but I can't find any documentation on these changes.

What I'd really like to know though, is what the best way to achieving the former functionality is?

== EDIT ==

I've noticed that even when calling {$smarty.current_dir} from the extending file, we still get the base-file's path and filename. This is quite a significant change from earlier versions, and quite serious in my case, because I can no longer write dynamic code to find the top-level file's path.

like image 619
cartbeforehorse Avatar asked Sep 26 '22 07:09

cartbeforehorse


1 Answers

This is probably result of latest change in smarty

Starting with version 3.1.28 template inheritance is no longer a compile time process.
All {block} tag parent/child relations are resolved at run time.

This does resolve all known existing restrictions (see below).

From smarty devs:

Versions < 3.1.28 did cache all template objects for performance to reuse them in case a sub-template was called several times. However it was a wasted of memory. 3.1.28 is optimized for size and speed and the internal template object handling is completely different. The $smarty->template_objects was removed.

When debugging is enabled some information like the template file path is can be found within the $smarty->_debug->template_data array.

Inheritance release notes: https://github.com/smarty-php/smarty/blob/master/INHERITANCE_RELEASE_NOTES.txt

New features: https://github.com/smarty-php/smarty/blob/master/NEW_FEATURES.txt

You can check if $smarty.template_object don't have data what you need.

like image 88
Paweł Mikołajczuk Avatar answered Nov 15 '22 12:11

Paweł Mikołajczuk