Re: [SMARTY] template resources and compile_check
| From: | M Mohr | Date: | Thu, 31 Oct 2002 13:26:24 +0000 |
| Subject: | Re: [SMARTY] template resources and compile_check | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6294@lists.php.net to get a copy of this message | ||
hello again,
On Thu, Oct 31, 2002 at 01:32:28PM +0100, M Mohr wrote:
> hello list,
>
> i was playing around with template resources and encountered the following
> problem:
>
> when i set compile_check to true, the template-source is fetched
> everytime i include the template (smarty_resource_test_source() is called).
>
> smarty_resource_test_mtime() is also called and returns an mtime that
> is definitely older than the compiled template.
>
> i would have expected, that the template-source is only fetched when
> the template changed (== is newer than the compiled template).
>
> is this a known issue? did i overlook another setting? is it worth having
> a look at the ressource-handling code to fix this?
>
>
> if i set compile_check to false everything works and the template-source
> is not fetched anymore, but this is not flexible enough for my purpose.
>
> any ideas?
>
> regards
> messju
i fixed it myself, but i had to patch Smarty.class.php :
--begin--
925c925
< $template_timestamp)) {
---
> $template_timestamp, true, false,
> $compile_path)) {
1022c1022
< function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp,
$get_source = true, $quiet = false)
---
> function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp,
> $get_source = true, $quiet = false, $compile_path=null)
1037,1046c1037,1053
< if ($get_source) {
< $resource_func =
$this->_plugins['resource'][$resource_type][0][0];
< $_source_return = $resource_func($resource_name, $template_source,
$this);
< } else {
< $_source_return = true;
< }
< $resource_func =
$this->_plugins['resource'][$resource_type][0][1];
< $_timestamp_return = $resource_func($resource_name, $template_timestamp,
$this);
< $_return = $_source_return && $_timestamp_return;
< break;
---
> $resource_func = $this->_plugins['resource'][$resource_type][0][1];
> $_timestamp_return = $resource_func($resource_name, $template_timestamp, $this);
> if ($get_source) {
> if ( $this->force_compile || ($this->compile_check &&
> (filemtime($compile_path) < $template_timestamp))
> ) {
> $resource_func = $this->_plugins['resource'][$resource_type][0][0];
> $_source_return = $resource_func($resource_name, $template_source, $this);
> } else {
> $_source_return = true;
> }
>
> } else {
> $_source_return = true;
> }
> $_return = $_source_return && $_timestamp_return;
> break;
--end--
it is somewhat ugly, since i had to add a parameter to
_fetch_template_info to do the filemtime-check before the
smarty_resource_xxx_source() call. maybe it can be done
more beautiful, but i would love to see such functionality
integrated in one of the next releases, since fetching
templates from external ressources can be time-consuming,
much more time-consumning than fetching their mtimes.
regards
messju