Title: Re: [Templates] Hooking into template file accesses

Apologies in advance for whatever bizarre formatting Outlook Web Access may have added to this.

> From: Paul Evans [mailto:[EMAIL PROTECTED]
> Sent: Wed 3/1/2006 8:17 PM
> To: Garrett, Philip (MAN-Corporate);
[email protected]
> Subject: Re: [Templates] Hooking into template file accesses
>
> On Tue, Feb 28, 2006 at 12:04:34PM -0500, Garrett, Philip (MAN-
> Corporate) wrote:
> > You could subclass Template::Provider::fetch and add your mtime
> > checking code to it. (*untested code*) e.g.
>
> <snip>
>
> I tried that; it worked exactly as I'd expected. :)
>
> > Then, every time you process a template, do this:
> >
> >     $provider->init_mtime();
> >     $template->process($template_name) || die $template->error;
> >     my $mtime = $provider->get_mtime();
> >
> > I hope the code doesn't have too many bugs in it.
>
> Ah, well, now you come to mention it.... :)
>
> The code does run and does work, in that after that line, $mtime does
> contain the latest modification date of any file it read. This is
> suitable for the FastCGI script to set the "Last-Modified" header for
> the HTTP response.

Good.

> But, the mtime is also needed earlier than that; I place it in a
> template variable, so the page template can put a "Last modified: .."
> footer on the bottom; thus:
>
>     Last modified: [% strftime( "%Y/%m/%d %H:%M:%S", mtime ) %]
>
> So the mtime has to be available earlier than this. But the problem
> is, how do we know what it will be without expanding the template? We
> could of course just expand the template twice; first time just to get
> the times, then again to actually run it. Seems rather wasteful
> though... Perhaps cache the results, so we can prefil the hash with
> what we think is likely the time, and only run it a second time if we
> noted a later time than we were expecting? Again, sounds quite
> wasteful though...

Agreed.

> So my question is really a matter of knowing exactly when the value
> from the variables hash will be read. If it is read sufficiently late,
> then all the code would need to do is update a reference to that
> particular hash element, and if it was looked at late enough, it
> should be fine. I do at least know the mtime of the actual page
> template, and of the WRAPPER template containing it, so I could start
> off with those. If the expansion is done late enough, the only things
> that would miss then would be any file INCLUDEd after the "Last
> modified:" line in the text. But that's near the bottom anyway, so it
> should be OK.

If there aren't any more INCLUDE/PROCESS/WRAPPER calls that fall after
your timestamp widget, it'll be fine.

I think you're on the right track here. You mentioned updating a hash,
but that seems like extra work. Why don't you just pass the provider
object as a variable into your template? Then you could just call the
get_mtime() method directly. Maybe that's what you meant...?

Philip

 

Reply via email to