View previous topic :: View next topic |
Author |
Message |
MVH Smarty n00b
Joined: 04 Mar 2011 Posts: 3
|
Posted: Fri Mar 04, 2011 8:02 pm Post subject: Option use_relative_paths in {include} and {extends} |
|
|
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 |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Fri Mar 04, 2011 8:12 pm Post subject: Re: Option use_relative_paths in {include} and {extends} |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 04, 2011 11:07 pm Post subject: |
|
|
The comming Smarty 3.1 version will support filepath specification relative to the calling template in {include...} |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Fri Mar 04, 2011 11:08 pm Post subject: |
|
|
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 |
|
Back to top |
|
Bon/V Smarty Rookie
Joined: 25 Feb 2011 Posts: 7
|
Posted: Sat Sep 03, 2011 3:45 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Sep 03, 2011 9:02 am Post subject: |
|
|
Relative path should work in Smarty3.1 RC |
|
Back to top |
|
Bon/V Smarty Rookie
Joined: 25 Feb 2011 Posts: 7
|
Posted: Sun Sep 04, 2011 2:04 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Sep 04, 2011 4:31 pm Post subject: |
|
|
That's the expected behavior. The file path are relative to the folder of the calling template. |
|
Back to top |
|
Bon/V Smarty Rookie
Joined: 25 Feb 2011 Posts: 7
|
Posted: Tue Sep 06, 2011 1:55 pm Post subject: |
|
|
Thanks.
This behavior is same at {include}.
So, I understood that is spec change from 2.x to 3.1. |
|
Back to top |
|
Onedamobamomi Smarty n00b
Joined: 08 Jul 2011 Posts: 4 Location: Greenland
|
Posted: Sat Oct 15, 2011 7:57 am Post subject: Option use_relative_paths in include and extends |
|
|
Write one.. THat is one of the best "features" of Rev, you can add whatever features you want.. |
|
Back to top |
|
|