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

Inherited template and $smarty.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 -> Add-ons
View previous topic :: View next topic  
Author Message
geoB
Smarty Regular


Joined: 09 Sep 2010
Posts: 46

PostPosted: Sun Jul 22, 2012 11:37 pm    Post subject: Inherited template and $smarty.template Reply with quote

It appears that
Code:
$smarty.template
inside a template returns the name of the outermost template rather than the name of the template containing that code.
For example, index.tpl contains:
Code:
{extends file="search_form.tpl"}
and search_form.tpl contains:
Code:

{extends file="layout.tpl"}
{assign value=$smarty.template|replace:'.tpl':'' var='formName'}
...
<input type="hidden" name="formName" value="{$formName}">

When the source of index.php is viewed, one sees that formName=index.
Is this by design or otherwise unavoidable?

Thanks.

George
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Jul 23, 2012 6:38 pm    Post subject: Reply with quote

Template inheritance is a compile time process where the source blocks of child and parent are replaced/merged together in one compiled template file.
{$smarty.template} will return always the name of the compiled template file which is in your case 'index.tpl'.

But why can't you just assign the string 'search_form' to variable $formName?
Back to top
View user's profile Send private message
geoB
Smarty Regular


Joined: 09 Sep 2010
Posts: 46

PostPosted: Thu Jul 26, 2012 8:50 pm    Post subject: Reply with quote

Thanks for your reply. That's what I ended up doing, figuring the explanation was most likely what you provided. Guess I was just trying to be too clever.

George
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 -> Add-ons 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