5

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.

cartbeforehorse
  • 3,045
  • 1
  • 34
  • 49
  • I think that now you need to move `file_name` block to child template `content.tpl` to get it filename. – Paweł Mikołajczuk Feb 24 '16 at 18:55
  • @PawełMikołajczuk No. I specifically say in my ==EDIT== block, that putting the same code in the child template, renders the parent's path and file name!! Crazy freaky, no? Major change to introduce in a minor release level. – cartbeforehorse Feb 24 '16 at 23:04
  • Ouć ;/ we use smarty in Newscoop but we stopped on 3.1.21. Latest changes are huge and they should be branded at least as 3.2.x or even 4.x. I'm afraid that now your use case is not possible (you can find info about changes in my answer) and best will be to downgrade to 3.1.27 – Paweł Mikołajczuk Feb 25 '16 at 07:52

1 Answers1

4

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.

Paweł Mikołajczuk
  • 3,692
  • 25
  • 32
  • I need to do more investigation on what you've said, but I have found a work-around for the time being, and the bounty time is coming to an end. Your answer is thorough though, so thank you. – cartbeforehorse Mar 02 '16 at 00:08