$ Smarty.current_dir value when called from an 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 printed the template name and file path: content.tpl .

However, I just upgraded to 3.1.29, and now it seems that this is the name of the main PageContentLayout.tpl file that is being printed.

I assume that this is a deliberate design change in different versions of Smarty, but I can not find documentation about these changes.

What would I really like to know, the best way to achieve the same functionality?

== EDIT ==

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

+5
source share
1 answer

This is probably the result of the 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 removes all known existing restrictions (see below).

From smarty developers:

Version < 3.1.28 cached all template objects to improve performance, so that they could be reused if the subpattern was called several times. However, it was a lost memory. 3.1.28 is optimized for size and speed, and the processing of internal templates is completely different. $smarty->template_objects has been deleted.

When debugging is enabled, you can find some information in the $smarty->_debug->template_data array, such as the path to the template file.

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 data you need.

+4
source

Source: https://habr.com/ru/post/1243599/


All Articles