|
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 |
Jerc Smarty Rookie
Joined: 26 Jan 2010 Posts: 30 Location: Slovenia / Ljubljana
|
Posted: Thu Apr 02, 2015 7:42 am Post subject: {extends} wrong template |
|
|
I found very odd bug or i missed something in the templates.
Files:
tpl/demo1/home.tpl
Code: | <p>demo1/home.tpl</p>
<p>{block name="customText"}Custom Text @ demo1/home.tpl{/block}</p>
{include file="head.tpl"} |
tpl/demo1/head.tpl
Code: | <p>demo1/head.tpl</p> |
tpl/demo1/sub/home.tpl
Code: | {extends file="../home.tpl"}
{block name="customText"}demo1/sub/home.tpl{/block} |
tpl/demo2/home.tpl
Code: | <p>demo2/home.tpl</p>
<p>{block name="customText"}Custom Text @ demo2/home.tpl{/block}</p>
{include file="head.tpl"} |
tpl/demo2/head.tpl
Code: | <p>demo2/head.tpl</p> |
index.php
Code: | $smarty = new Smarty();
$smarty->setTemplateDir(
array(
'tpl/demo2',
'tpl/demo1'
)
);
$smarty->setCompileDir(
'tpl/compile'
);
$smarty->setCacheDir(
'tpl/cache'
);
$smarty->display('sub/home.tpl'); |
So, problem is, that in demo2/sub/home.tpl does not exist. Smarty found the template in the demo1/sub folder and used it. All fine till here. The {extends} extended the template in demo1 folder. I was expecting that it will extend the template in demo2 folder.
Here is the output of the code above:
Code: | demo1/home.tpl
demo1/sub/home.tpl
demo2/head.tpl |
If I create demo2/sub/home.tpl file with {extends file="../home.tpl"}, then I get my expected output:
Code: | demo2/home.tpl
Custom Text @ demo2/home.tpl
demo2/head.tpl |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Apr 02, 2015 3:52 pm Post subject: |
|
|
{extends} is relative to the current template.
The idea behind this is that you can have a base theme, and a theme built upon it, but not the intermix of both.
Consider "protected" vs. "private" property.
You'll have to create demo2/sub/home.tpl if you want to keep using the demo2 inheritance path. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Apr 04, 2015 8:38 pm Post subject: |
|
|
AnrDaemon wrote: | {extends} is relative to the current template.
The idea behind this is that you can have a base theme, and a theme built upon it, but not the intermix of both.
Consider "protected" vs. "private" property.
You'll have to create demo2/sub/home.tpl if you want to keep using the demo2 inheritance path. |
This is not correct. {extends} itself is not relative to the current template.
But all relative path specifications like "../home.tpl" are.
tpl/demo1/sub/home.tp
l Code: | {extends file="home.tpl"}
{block name="customText"}demo1/sub/home.tpl{/block} |
should solve the problem. |
|
Back to top |
|
Jerc Smarty Rookie
Joined: 26 Jan 2010 Posts: 30 Location: Slovenia / Ljubljana
|
Posted: Tue Apr 07, 2015 9:51 am Post subject: |
|
|
U.Tews wrote: |
tpl/demo1/sub/home.tpl
Code: | {extends file="home.tpl"}
{block name="customText"}demo1/sub/home.tpl{/block} |
should solve the problem. |
Thanks for the solution. |
|
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
|