|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
loopsys_dad Smarty Rookie
Joined: 10 Nov 2010 Posts: 11
|
Posted: Tue Nov 16, 2010 12:07 am Post subject: template inheritance |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Nov 16, 2010 12:47 am Post subject: |
|
|
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 |
|
loopsys_dad Smarty Rookie
Joined: 10 Nov 2010 Posts: 11
|
Posted: Tue Nov 16, 2010 5:04 am Post subject: |
|
|
[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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Nov 16, 2010 1:49 pm Post subject: |
|
|
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 |
|
|
|
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
|