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

Problem with compile filepath
Goto page Previous  1, 2, 3  Next
 
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
U.Tews
Administrator


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

PostPosted: Wed Feb 02, 2011 9:28 am    Post subject: Reply with quote

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
View user's profile Send private message
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Wed Feb 02, 2011 9:35 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Feb 02, 2011 9:41 am    Post subject: Reply with quote

We are currently still working on some optimzations. But I exspect the release of 3.1 during this month.
Back to top
View user's profile Send private message
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Wed Feb 02, 2011 9:49 am    Post subject: Reply with quote

Thank you! I will wait.
Back to top
View user's profile Send private message
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Wed Feb 02, 2011 10:03 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Feb 02, 2011 10:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Wed Feb 02, 2011 11:59 am    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


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

PostPosted: Wed Feb 02, 2011 12:02 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Thu Jul 07, 2011 6:09 am    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


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

PostPosted: Thu Jul 07, 2011 7:58 am    Post subject: Reply with quote

The code for resolving /foo/bar/./../baz/bla.tpl to /foo/baz/bla/tpl is already in place: http://code.google.com/p/smarty-php/source/browse/branches/Smarty_3_1_DEV/distribution/libs/sysplugins/smarty_resource.php#157

does that not satisfy your needs?
Back to top
View user's profile Send private message Visit poster's website
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Thu Jul 07, 2011 5:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


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

PostPosted: Thu Jul 07, 2011 5:12 pm    Post subject: Reply with quote

./ 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
View user's profile Send private message Visit poster's website
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Thu Jul 07, 2011 9:27 pm    Post subject: Reply with quote

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
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 7:42 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Loki
Smarty Rookie


Joined: 13 Jan 2011
Posts: 30

PostPosted: Fri Jul 08, 2011 8:04 am    Post subject: Reply with quote

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
View user's profile Send private message
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
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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