[Zope] Re: Adding Custom Namespaces to ZPT?

Evan Simpson evan@4-am.com
Fri, 30 May 2003 11:44:55 -0500


Hartmut Goebel wrote:
> I want to add custom namespaces and/or entities to ZPT. How can I do 
> this? I tried searching the web, but did not find a sollution.
> 
> What I want to do is something like this:
> 
>   <my-ns:email name="Egon Meier" />
> or
>   &author;   # link to author's mail-address

Interesting.  ZPT's implementation doesn't have any way of supporting 
this, although one or more of the alternate TAL implementations may be 
more easily extensible.

You're essentially trying to make your own mini-language here, and while 
I won't dispute that this would be useful for you, a generalized version 
of this capability would take a lot of thought.  Your best bet may well 
be a quick&dirty hack along the lines of inserting regex-based search 
and replace on your templates before they're compiled.  Something along 
the lines of (WARNING: UNTESTED!):

txt = re.sub(r'<my-ns:([A-Za-z]+) ([^>]*)>',
              r'<tal:my-ns replace="python:ms-ns.\1(\2)" />',
              txt)
txt = re.sub(r'&my-([A-Za-z]]+);',
              r'<tal:my-ent replace="\1" />',
              txt)

You could patch or monkey-patch a call to your transformation into 
PageTemplate.py's _cook() method.

Cheers,

Evan @ 4-am