[Petal] [IDEA] Hash with params

Evan Simpson evan at 4-am.com
Wed Sep 10 22:01:32 BST 2003


Jean-Michel Hiver wrote:
> Gotcha! Brilliant idea. Now that I understand what it is about, I think
> it'll be rather easy to implement with Petal. You'll be able to stack
> prefixes too, which is a Petal feature suggested by William some time
> ago.

Thanks, but I'm not sure what you mean by "stacking".  It's certainly 
valid to write something like "x/var:y/item:0/key:fred", if that's what 
you're getting at.

> It would be nice if this prefix business allowed parameters to be passed
> to methods, functionality which I find very useful. I would really like
> some kind of formal syntax allowing this kind of stuff in TALES. I guess
> prefixes in paths is a nice step in the right direction!

There's a builtin 'call' prefix in the ZPT implementation.  It accepts a 
list of variable names to pass as positional arguments to the current 
object, like so: "mymethod/call:x, y, z".  This doesn't allow for named 
arguments or expressions, but parsing is easy.

> Am I right in seeing METAL as some kind of 'meta-template'?

Well, the name is Macro Expansion TAL, which shows how I see it :-)

> As far as I can see, define-slot is only really some sort of
> 'tal:define_variable_with_current_xml_node' while fill-slot boils down
> to a 'tal:replace_structure_unless_not_defined'.

Except that macro names live in their own namespaces, completely 
separate from variables, and slot names are merely markers for nodes. 
The abstract idea is that the template and macros are combined into a 
notional intermedate template, which is then executed.  That's not how 
we implement it, of course.

> define-macro serves as an indentifier. Which makes me think: Why not use
> a more standard syntax for XML / HTML fragments in URLs when you do
> includes? (i.e. use-macro="my/file.xml#mymacro").

Because we tried to use as little syntax as possible, and 
".../macros/mymacro" is very natural in a Zope context.  YMMV, of course.

> and use-macro is just an include statement, except that it defines all
> the fill-slot variables before doing the includes.
> 
> Have I got it right?

Given a loose definition of "variables", yes.

> If / When this is implemented with Petal, the following macro should be
> possible:
> 
> <ul tal:define="child self/root">
>   <li metal:define-macro="sitemap_li">
>     <a
>       href="#"
>       hreflang="en"
>       lang="en"
>       xml:lang="en"
>       tal:attributes="href child/Full_Path;
>                       hreflang child/Lang;
>                       lang child/Lang;
>                       xml:lang child/Lang"
>       tal:content="child/Title"
>     >Child Document Title</a>
>     <ul
>       petal:define="children child/Children"
>       petal:condition="children"
>       petal:repeat="child children"
>     >
>       <li metal:use-macro="#sitemap_li" />
>     </ul>
>   </li>
> </ul>

Yipe!  That looks infinitely recursive to me.  Did you really mean to 
use the macro inside its own definition?

Cheers,

Evan @ 4-am



More information about the Petal mailing list