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

template inheritance

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
loopsys_dad
Smarty Rookie


Joined: 10 Nov 2010
Posts: 11

PostPosted: Tue Nov 16, 2010 12:07 am    Post subject: template inheritance Reply with quote

I am wondering what is the logic of having this tag in child templates:

{extends file="parent.tpl"}

The point is that when one chains a template in code:

$createTemplate($file2, $cache_id = null, $compile_id = null, $parent = $file1)
OR
$smarty->display("extends:$file1|$file2")

the inheritance is already specified. now the extends tag in the child template seems redundant. If anything, it seems to restrict the reusability of a template in inheritance chains.

As a suggestion, perhaps child templates can contain only {block name=}{/block} tags in future releases, and the {extends file=} tag should become optional.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Nov 16, 2010 12:47 am    Post subject: Reply with quote

There are two way to use template inheritance.

1.
$smarty->display("extends:$file1|$file2")

Here you define the child/ parent template relations by the template files listed. These template files need no {extends...} tags.

2.
$smarty->display("cild.tpl")
Here the parent template is define by a {extends file='parent.tpl'}
in the child template.

You can do it either way.

With the {extends...} tag you can also start template inheritance chains within subtemplates. They must not start in the main template.

If you use the first option any {extends } tags in the template files get ignored.
Back to top
View user's profile Send private message
loopsys_dad
Smarty Rookie


Joined: 10 Nov 2010
Posts: 11

PostPosted: Tue Nov 16, 2010 5:04 am    Post subject: Reply with quote

[code]
$parent = $smarty->createTemplate( $tplfile1 );
$child = $smarty->createTemplate( $tplfile2, NULL, NULL, $parent );
$child->display();
[/code]

In this case, we have created the parent child relationship in OO php code.

Does $tplfile2 need to start with the {extends} block? In my opinion, the {extends} block should NOT be required in this scenario.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Nov 16, 2010 1:49 pm    Post subject: Reply with quote

This is wrong usage for template inheritance. The $parent parameter of the
createTemplate() method has nothing to do with parent/child relationsship of template inheritance. You have to use one of the two methods mentioned in my earlier post.

It's used to used as an uplink pointer for chained variable scopes.
See http://www.smarty.net/docs/en/language.variable.scopes
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 -> Feature Requests 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