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

Different bases for relative paths

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Thu Jul 07, 2011 9:20 pm    Post subject: Different bases for relative paths Reply with quote

$template_dir = /some/path
template /some/path/sub/test.tpl

test.tpl
Code:
{include file="../main.tpl"}
{include file="main.tpl"}


In the case {include file="../main.tpl"} path starts from the current directory
/some/path/sub/../main.tpl

But in the case of {include file="main.tpl"} path starts from $template_dir
/some/path/main.tpl

Version 3.1

Is it normal?


Last edited by Loki on Fri Jul 08, 2011 4:17 pm; edited 1 time in total
Back to top
View user's profile Send private message
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Fri Jul 08, 2011 3:28 pm    Post subject: Reply with quote

/root/sub/bar.tpl
Code:
{include file="../foo.tpl"} {*try to load template in root*}
{include file="foo.tpl"} {*try to load template in sub*}

/root/foo.tpl
Code:
<p>foo in root</p>

/root/sub/foo.tpl
Code:
<p>foo in sub</p>


Code:
$smarty = new Smarty;
$smarty->setTemplateDir('/root');
$smarty->display('sub/bar.tpl');


result is
Code:
foo in root
foo in root


It seems that this is a bug.

http://smarty-php.googlecode.com/svn/branches/Smarty_3_1_DEV
revision 4204
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Fri Jul 08, 2011 5:42 pm    Post subject: Re: Different bases for relative paths Reply with quote

Loki wrote:
Is it normal?


this is not only normal, but expected.

{include file="foo,tpl"}
translates to $smarty->fetch("foo.tpl") - thus regularly walking through the template_dir array

{include file="../foo,tpl"}
translates to $smarty->fetch(dirname($AbsolutePathOfCurrentTemplate) .'/../foo.tpl'); - thus only adressing one specific file relative to the current template.

This is (briefly) mentioned in the 3.1 notes: http://code.google.com/p/smarty-php/source/browse/branches/Smarty_3_1_DEV/distribution/SMARTY_3.1_NOTES.txt#191
Back to top
View user's profile Send private message Visit poster's website
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 -> Smarty Development 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