Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Extended templates and use of $smarty.current_dir/.template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
cartbeforehorse
Smarty n00b


Joined: 17 Feb 2016
Posts: 4

PostPosted: Mon Feb 22, 2016 4:37 pm    Post subject: Extended templates and use of $smarty.current_dir/.template Reply with quote

My code is as follows:

content.tpl:
Code:

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


PageContentLayout.tpl
Code:

{* 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. However, what I'd like to know is what the best way to achieving the former functionality is?

Thanks,
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Feb 22, 2016 10:50 pm    Post subject: Reply with quote

Your template doesn't exactly says what is the functionality you want to achieve. Knowing real filesystem path is of no concern for template.
If you need some debug data, enable debugging. It will be there.
Back to top
View user's profile Send private message
cartbeforehorse
Smarty n00b


Joined: 17 Feb 2016
Posts: 4

PostPosted: Tue Feb 23, 2016 11:58 pm    Post subject: Reply with quote

AnrDaemon wrote:
Your template doesn't exactly says what is the functionality you want to achieve. Knowing real filesystem path is of no concern for template.
If you need some debug data, enable debugging. It will be there.


I'm not sure that it really matters why I'm asking how this works. Clearly it is important for me to be able to retrieve the "path/filename" of the extending template (rather than the extended template), else I wouldn't be asking the question!

Since you did ask: the framework I'm using uses the name of the file to pass back to PHP, in order to call a class of the same name as the template file. This only works if the filename is derived from the extending file!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Feb 26, 2016 11:46 pm    Post subject: Reply with quote

In Smarty versions below template inheritance was a compile time process and the resulting code was merged into one compiled template file, in your case the content compiled template. This did have a lot of restrictions an short comings.

Since 3.1.28 it's a run time process child and parent template have their own compiled template files. Now {$smarty.template} does return the logical correct answer because it's called in PageContentLayout.
Solution

content.tpl
Code:
{extends file='PageContentLayout.tpl'}
{$dir = $smarty.current_dir}
{$template = $smarty.template}


PageContentLayout.tpl
Code:
{block name="file_name"}
<p>{$dir}</p>
<p>{$template}</p>
{/block}


Read the INHERITANCE_RELEASE_NOTES
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP