[Zope] Custom rendering

Alexander Staubo alex@mop.no
Tue, 15 Jun 1999 18:55:32 +0200


I'd like to see a simpler way to implement custom "formatters", or
"renderers" if you will. Please stop me if there exists a similar
technology out there, bar structured text. If not, bear with me.

Here's an example to illustrate what I need. All over my sites I have
bits and pieces that should render consistently, but the HTML code
needed is sufficiently complex that I prefer to relegate this code to a
centralized method. Consider, for example:

  <p><font size="3"><b><span class="heading">News</span></b></font><br>

In this case I might write a DTML Method that looks like this:

  <p><font size="3"><b><span
    class="heading"><!--#var Heading--></span></b></font><br>

And which is invoked thus:

  <!--#var "RndHeading(Heading = 'News')"-->

which is okay except when the Method might need some data from the
common namespace, in which case I must call it like so:

  <!--#var "RndHeading(REQUEST, PARENTS, Heading = 'News')"-->

or whatever. (Really, is there no way to pass the top namespace?)

Anyway, if we assume that this is good practice -- the objective here is
to separate style from content -- maybe we could invent the notion of a
Render Method.

I imagine the syntax could be something like

  <!--#render fmt="Heading"-->News<!--#/render-->

or, as an alternative syntax

  <!--#render text="News" fmt="Heading"-->

And an example of passing arguments to the rendering method:

  <!--#render text="News" fmt="Heading(size = 3)"-->

The Render Method could be a special object, otoh it could be just any
callable object. Maybe rendering should not be limited to text, either,
but any object that could be rendered by Zope.

Afaik, today the only way to extend the <!--#var obj fmt=foo-->
mechanism is to implement the method "foo" on the object "obj", and you
can't easily do this with a piece of text. This is often useful, but
not, I think, in the context of what seek to accomplish.

--
Alexander Staubo             http://www.mop.no/~alex/
"`This must be Thursday,' said Arthur to himself, sinking low over
his beer, `I never could get the hang of Thursdays.'"
--Douglas Adams, _The Hitchhiker's Guide to the Galaxy_