View previous topic :: View next topic |
Author |
Message |
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 02, 2011 9:28 am Post subject: |
|
|
Anyway there will be some changes in filepath handling in the upcomming version 3.1. We will see how this problem could be solved in the same run. |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Wed Feb 02, 2011 9:35 am Post subject: |
|
|
U.Tews wrote: | Anyway there will be some changes in filepath handling in the upcomming version 3.1. |
Can I expect these changes soon in svn? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 02, 2011 9:41 am Post subject: |
|
|
We are currently still working on some optimzations. But I exspect the release of 3.1 during this month. |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Wed Feb 02, 2011 9:49 am Post subject: |
|
|
Thank you! I will wait. |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Wed Feb 02, 2011 10:03 am Post subject: |
|
|
Another idea: it may be possible to cache the path of existing templates in the file?
Something like that:
Code: |
public function buildTemplateFilepath ($file = null)
{
if ($this->tpl_cache[$file]) return $this->tpl_cache[$file];
....
}
|
In this case, will not have to check each time a template.
Now you every time check that template exists, even when the compile check is disabled |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 02, 2011 10:25 am Post subject: |
|
|
This is not possible as template_dir can be an array which is scanned if you call display('my.tpl');
We need to get the path of the matching array element.
For that reasion we can't skip the test.
$this->tpl_cache[$file] does not make sense anyway, as the template objects are already cached for cases when same template is called several times and buildTemplateFilepath is just called once. |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Wed Feb 02, 2011 11:59 am Post subject: |
|
|
U.Tews wrote: | This is not possible as template_dir can be an array which is scanned if you call display('my.tpl');
We need to get the path of the matching array element.
For that reasion we can't skip the test. |
Code: | public function buildTemplateFilepath ($file = null)
{
foreach($this->template_dir as $dir)
if (CacheClass::$tpl_cache[$dir][$file]) return CacheClass::$tpl_cache[$dir][$file];
....
} |
Think its good idea to store data like this in one place. With a lot of templates it's significantly. Also you can store in $tpl_cache[$dir][$file] absolute path to template, therefore different relative paths will not lead to different compiled files. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Wed Feb 02, 2011 12:02 pm Post subject: |
|
|
If you resolve the relative filepaths with one of the algorithms we've posted here already, you should not need to cache anything outside the template. Internally the caching layer works differently anyways… |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Thu Jul 07, 2011 6:09 am Post subject: |
|
|
I made function canonicalPath (see code of globe at first page) and made some changes in sysplugins/smarty_internal_template.php
In method buildTemplateFilepath I changed all "return $some_file;" to "return canonicalPath($some_file);"
Seems it's work fine. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Thu Jul 07, 2011 5:04 pm Post subject: |
|
|
Woks strange:
Code: |
include 'smarty/Smarty.class.php';
$smarty=new Smarty();
//set absolute path for template dir
$smarty->setTemplateDir(dirname(__FILE__).'/tpl/baseSkin');
//try to use relative path
//becomes Exeption "Template '../otherSkin/main.tpl' may not start with ../ or ./'"
//WHY NOT?!
$smarty->display('../otherSkin/main.tpl');
//OK let's try using SAME template again
//we've got another compiled file
$smarty->display(dirname(__FILE__).'/tpl/baseSkin/../otherSkin/main.tpl');
//well, we changed some templates and want to update compiled files (becouse compile check is off)
$smarty->setTemplateDir(dirname(__FILE__).'/tpl/otherSkin');
$smarty->compileAllTemplates();
//Oops - we got one more compiled file
|
After comment exeption string, under win we got TWO compiled files:
Code: | 0 => 'Z:\\home\\test.local\\www/tpl/otherSkin\\main.tpl'
and
0 => 'Z:\\home\\test.local\\www\\tpl\\otherSkin\\main.tpl' |
|
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Thu Jul 07, 2011 5:12 pm Post subject: |
|
|
./ and ../ are not allowed in ->fetch() and ->display() as they cannot be relative to a template source. They would have to be relative to the current working directory (usually a bad idea) or relative to SMARTY_DIR (yet another bad idea). Thus they exception out.
absolute paths (as created when using dirname(__FILE__)) are not handled by the relative-path-resolver.
as for / vs. \\ - try using the proper DIRECTORY_SEPERATOR for your operating system. |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Thu Jul 07, 2011 9:27 pm Post subject: |
|
|
globe wrote: | have to be relative to the current working directory (usually a bad idea) or relative to SMARTY_DIR (yet another bad idea). |
In previous versions relative path starts from $smarty->template_dir. How is this idea bad? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Fri Jul 08, 2011 7:42 am Post subject: |
|
|
Loki wrote: | globe wrote: | have to be relative to the current working directory (usually a bad idea) or relative to SMARTY_DIR (yet another bad idea). |
In previous versions relative path starts from $smarty->template_dir. How is this idea bad? |
$smarty->template_dir is an array. |
|
Back to top |
|
Loki Smarty Rookie
Joined: 13 Jan 2011 Posts: 30
|
Posted: Fri Jul 08, 2011 8:04 am Post subject: |
|
|
globe wrote: | $smarty->template_dir is an array. |
include_path in php.ini also contents several paths and it works well. So it's strange argument about an array. |
|
Back to top |
|
|