[Web-SIG] Standardized template API

Clark C. Evans cce at clarkevans.com
Tue Jan 31 20:03:50 CET 2006


On Tue, Jan 31, 2006 at 10:48:53AM -0600, Ian Bicking wrote:
| Kevin Dangoor wrote:
| >>>[1] http://www.turbogears.org/docs/plugins/template.html
| >>
| >>I concur.  I've started using it in a project of mine.  There's a couple
| >>things I'd like to add that have come up on the TG list:
| >>
| >>* Add "template_file" and "template_string" arguments to .render(),
| >>which take filenames and strings.
| > 
| > Would template_file be expecting an absolute filename? (just
| > confirming that this wouldn't do any more lookups or path searching...
| > just open and go!)
| 
| I'm thinking if it is an absolute filename, it should be treated as an 
| exact reference.  If not, then you search for the file in the search 
| path.  Though maybe that logic should be in find_template.  For 
| instance, sometimes you might want to force the template to be under 
| some base directory (e.g., for security reasons), so find_template might 
| treat absolute filenames as relative to that directory.

I'd stick with the notion of a "template_name" that is neither the
template file nor the template body.  Then you'd want a template factory
method that takes the name and produces the template body (complied if
necessary).  This needs to be once indirect since a template may refer
to other sub-templates. This way your template could be stored
in-memory, on-disk, or in a database, or even remotely using an HTTP
cashe.  The actual storage mechanism for the template source code should
not be part of this interface.

Best,

Clark


More information about the Web-SIG mailing list