Mailing List Archive

[Zope-PTK] Re: DISCUSS: Changing template construction
Christopher Petrilli wrote:

> Here's the format we talked about:

> <dtml-component template="component_template_name"
> insertAs="content"> ... ... ... </dtml-component>

<snip>

> * Should there be a default 'template'? We don't know :-)
Also, can you pass additional arguments into the template? I
occasionally end up calling the standard header and footer with
explicit arguments.

Assuming that dtml-component is just like any other tag and can be
used freely wherever you want, here are a few other things that
might be possible, or might not be possible depending on how it is
implemented (and if you feel any of them might be considered
component abuse feel free to say):

Given a dtml method called stx with a body of:
<dtml-var name="template_contents" fmt="structured-text">
you could embed a chunk of structured text in the middle of a
method just by sticking:
<dtml-component template="stx">
... some structured text here ...
</dtml-component>
at any suitable position.

If template is allowed to be blank (or failing that if you use a dummy
method with an empty body, then you get a way to lay out large
chunks of DTML neatly without generating any output (even spaces):
<dtml-component template="">
<dtml-if ....>
... 95 lines of DTML in here! ...
</dtml-if>
</dtml-component>

Other fun methods for use as templates could aggressively remove
varying degrees of whitespace (I can think of uses for removing all
whitespace, all multiple spaces, or all whitespace directly following a
'>').

Getting a bit more obscure, you now have a general way to assign
the output of some dtml into a variable for further processing.

Finally, and this *must* be component abuse, it ought to be possible
to write an external method that takes template_contents, does a
global replace of the value in template_tag (or 'DTML' if it isn't
defined) into dtml, and then evaluates the result as a block of dtml.
This would let you do things like sorting on a variable column:
<dtml-component template="evaldtml">
<DTML-in name="somequery" sort="&dtml-sortcolumn;">
<DTML-col1> <DTML-col2>
</DTML-in>
</dtml-component>

--
Duncan Booth duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan