[Catalyst] Fetching URL Content

Trevor Phillips trevor.phillips at gmail.com
Thu Sep 3 01:25:39 GMT 2009

I have a requirement to fetch URL content - this is currently mostly
to do with the View phase, to include chunks of HTML for core branding
in the templating. ie; Top header, footer, global nav, that sort of

Ideally, I'd like to do it directly from the Template Toolkit
templates, but TT either can't do this, or it's really hard to Google
for. ^_^
It would be nice to cache locally the content, even if for a short
period. Or ideally, to cache permanently unless there's a
"Cache-Control: no-cache" request header to force an update.

ie; something like:
   [% INCLUDE "http://central.server.com/branding/header.html" cache="5 min" %]

Can TT do anything like this? It doesn't need to be parsed by TT
(although having the option for TT to parse it would be useful).

The next idea would be to have a Controller fetch the content for the
remote URLs, and either shove them in the stash, or cache them to
disk, so that TT can then reference them. Would this just be a case of
doing a usual LWP UserAgent Request, or does Catalyst have built-in
handling or plugins to aid in this?

Hmmm. It could be implemented as a Model as well, I guess...

Any ideas/tips/best practices?


Trevor Phillips  - http://dortamur.livejournal.com/
"On nights such as this, evil deeds are done. And good deeds, of
course. But mostly evil, on the whole."
      -- (Terry Pratchett, Wyrd Sisters)

More information about the Catalyst mailing list