Re: [SMARTY] Newbie question... last modified timestamp
| From: | Andrei Zmievski | Date: | Tue, 16 Apr 2002 16:45:17 +0000 |
| Subject: | Re: [SMARTY] Newbie question... last modified timestamp | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3774@lists.php.net to get a copy of this message | ||
The problem is that {last_modified} is a compiler function, and at
compilation time nothing is known about $PageTemplate. You could modify
the func as follows:
function ........
{
....
if (empty($args['template']))
$tpl_file = $smarty->_current_file;
else
$tpl_file = $smarty->_dequote($args['template']);
...
return "echo strftime($format, filemtime(\$this->template_dir . '/$tpl_file))";
}
On Tue, 16 Apr 2002, Mieu d'Iscalio Sedai wrote:
> Ah, I hadn't really looked into plugins at this point, but this will work
> nicely with some modification. Thank you Andrei. I'm having another problem
> though, because I'm trying to modify your function to take a "template"
> argument so that I can retrieve the time any template was modified.
>
> All I really did was change the line
>
> $lastmod = filemtime($smarty->template_dir . '/' . $smarty->_current_file);
>
> to
>
> if (empty($args['template']))
> $lastmod = filemtime($smarty->template_dir . '/' .
> $smarty->_current_file);
> else
> $lastmod = filemtime($smarty->template_dir . '/' .
> $args['template']);
>
> In my index.php I assign the value for the variable $PageTemplate, which is
> the template containing the body of the page currently being displayed. (The
> filename of this template is relative to the Smarty $template_dir variable.)
> So, in my footer.tpl I call the plugin with
>
> {last_modified template=$PageTemplate}
>
> If I type in index.php?page=something in my browser, something.tpl is
> assigned to $PageTemplate. And when the plugin is executed, it should (at
> least according to my weird logic) then return the last modified time for
> something.tpl. However, I'm getting errors for this, specifically:
>
> Warning: stat failed for
> /home/.../www/smarty/templates/$this->_tpl_vars['PageTemplate'] (errno=2 -
> No such file or directory) in
> /home/www/.../smarty/plugins/compiler.last_modified.php on line 15
>
> Parse error: parse error in
> /home/www/.../smarty/templates_c/239/239105369/0.php on line 23
>
> I'm not sure if this is just some silly syntax error, or if I'm doing
> something seriously wrong in my code. I'd appreciate any help you or others
> can give. Thanks again!
>
> Sally
>
> P.S. Below is the original compiler.last_modified function you wrote.
>
> ----- Original Message -----
> From: "Andrei Zmievski" <andrei@ispi.net>
> To: "Mieu d'Iscalio Sedai" <mieu@ix.netcom.com>
> Cc: <smarty-general@lists.php.net>
> Sent: Tuesday, April 16, 2002 6:12 AM
> Subject: Re: [SMARTY] Newbie question... last modified timestamp
>
> > function smarty_compiler_last_modified($arg, &$smarty)
> > {
> > $args = $smarty->_parse_attrs($arg);
> >
> > $lastmod = filemtime($smarty->template_dir . '/' .
> $smarty->_current_file);
> > if (empty($args['format']))
> > $format = '"%c %Z"';
> > else
> > $format = $args['format'];
> >
> > return "echo strftime($format, $lastmod);";
> > }
> >
> > ?>
> >
> > Just put it in a file called compiler.last_modified.php in your plugins
> > directory.
> >
> > -Andrei
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
-Andrei
* 2 + 2 = 5 for extremely large values of 2. *