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

Option use_relative_paths in {include} and {extends}

 
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
MVH
Smarty n00b


Joined: 04 Mar 2011
Posts: 3

PostPosted: Fri Mar 04, 2011 8:02 pm    Post subject: Option use_relative_paths in {include} and {extends} Reply with quote

In big projects, where many template files, full path to template input so hard.
Example:
Project structure:
Code:
layouts/
    base.tpl
modules/
    catalog/
        goods/
            inc/
                price.tpl
            item.tpl
            list.tpl



item.tpl
Code:
<h1>Good Name</h1>
{include file="modules/catalog/goods/inc/price.tpl"}


But if we have option use_relative_paths (in Smarty class), we can write simple:
item.tpl
Code:
<h1>Good Name</h1>
{include file="inc/price.tpl"}
{* If needs absolute path, start it with slash: *}
{include file="/modules/catalog/goods/inc/price.tpl"}
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Fri Mar 04, 2011 8:12 pm    Post subject: Re: Option use_relative_paths in {include} and {extends} Reply with quote

You can use relative paths. Paths are relative to the template_dir. I'm not sure what directory you are expecting the paths to be relative to.

If you want to use a path relative to the current template you may use this plugin to get the template's directory (smarty 2):

http://www.smarty.net/forums/viewtopic.php?p=68822

Code:

{current_dir assign=dir}
{include file="`$dir`/inc/price.tpl"}


OR if you are using smarty 3 then you may get the current directory from
$smarty.current_dir I think
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Mar 04, 2011 11:07 pm    Post subject: Reply with quote

The comming Smarty 3.1 version will support filepath specification relative to the calling template in {include...}
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Fri Mar 04, 2011 11:08 pm    Post subject: Reply with quote

U.Tews wrote:
The comming Smarty 3.1 version will support filepath specification relative to the calling template in {include...}


ok cool... I spoke too soon then Smile
Back to top
View user's profile Send private message
Bon/V
Smarty Rookie


Joined: 25 Feb 2011
Posts: 7

PostPosted: Sat Sep 03, 2011 3:45 am    Post subject: Reply with quote

I think 3.1 RC is not support relative path yet...

ex.
{include file="./subdir1/temp.tpl"}
{extends file="../subdir2/temp.tpl"}
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Sep 03, 2011 9:02 am    Post subject: Reply with quote

Relative path should work in Smarty3.1 RC
Back to top
View user's profile Send private message
Bon/V
Smarty Rookie


Joined: 25 Feb 2011
Posts: 7

PostPosted: Sun Sep 04, 2011 2:04 pm    Post subject: Reply with quote

Thanks for your reply.

I think that the following points are different.

Assuming the following constitution.

ROOT => $smarty->display('test.tpl') on here.
|
+-- subdir => base.tpl on here.
|
+-- templates => test.tpl on here.

At test.tpl:
*Until Trunk Rev.4048
{extends file="./subdir/base.tpl"} {* => work fine *}

*3.1 RC1
{extends file="./subdir/base.tpl"} {* => NOT work *}
{extends file="../subdir/base.tpl"} {* => work fine *}

So, It's only different from '.' and '..'.
Do I misunderstand...?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Sep 04, 2011 4:31 pm    Post subject: Reply with quote

That's the expected behavior. The file path are relative to the folder of the calling template.
Back to top
View user's profile Send private message
Bon/V
Smarty Rookie


Joined: 25 Feb 2011
Posts: 7

PostPosted: Tue Sep 06, 2011 1:55 pm    Post subject: Reply with quote

Thanks.

This behavior is same at {include}.
So, I understood that is spec change from 2.x to 3.1.
Back to top
View user's profile Send private message
Onedamobamomi
Smarty n00b


Joined: 08 Jul 2011
Posts: 4
Location: Greenland

PostPosted: Sat Oct 15, 2011 7:57 am    Post subject: Option use_relative_paths in include and extends Reply with quote

Write one.. THat is one of the best "features" of Rev, you can add whatever features you want..
Back to top
View user's profile Send private message Send e-mail
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