[Petal] macro substitution?

Corey corey_s at qwest.net
Thu Apr 6 02:27:47 BST 2006


The following works for me, but seems... not very elegant ...


.../index.html
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

<head>
  <title>Foo or Bar?</title>
</head>

<body>

<span petal:condition="true: foo">
  <span metal:use-macro="dir/foo.html#body" petal:omit-tag=""></span>
</span>

<span petal:condition="true: bar">
  <span metal:use-macro="dir/bar.html#body" petal:omit-tag=""></span>
</span>

</body>

</html>


.../dir/foo.html
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

<head>
  <title>Foo</title>
</head>

<body>

<span metal:define-macro="body">
   <p>FOO!</p>
</span>

</body>

</html>



On Wednesday April 5 2006 5:03 pm, Corey wrote:
> 
> Hello!
> 
> I'm new to petal - have a question regarding best-practices, specifically regarding
> metal includes/macros.
> 
> In summary, I want to be able to dynamically utilize 'metal:use-macro', so that my
> calling cgi can set a variable, which will be passed to a base/common petal template,
> which will then use the intended macro, as defined/set in the aformentioned variable.
> 
> Say I have:
> 
> .../dir/foo.html
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
> 
> <head>
>   <title>Foo</title>
> </head>
> 
> <body metal:define-macro="body">
>    <p>FOO!</p>
> </body>
> 
> </html>
> 
> 
> and I also have a:
> 
> .../dir/bar.html
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
> 
> <head>
>   <title>Bar</title>
> </head>
> 
> <body metal:define-macro="body">
>    <p>BAR!</p>
> </body>
> 
> </html>
> 
> 
> finally, I have a:
> 
> .../index.html
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
> 
> <head>
>   <title>Foo or Bar?</title>
> </head>
> 
> <body metal:use-macro="dir/bar.html#body" petal:omit-tag="">
> 
> </body>
> 
> </html>
> 
> 
> Here's the question:
> 
> What's the best/proper way of changing that use-macro include in 'index.html' to
> dynamically decide on which macro to use - for instance if I have a variable defined,
> say, $action, which is either 'foo.html' or 'bar.html'?
> 
> Basically, somthing along the lines of the following ( which doesn't work ):
> 
> <body metal:use-macro="dir/${action}#body" petal:omit-tag="">
> 
> 
> 
> Many thanks!
> 
> 
> 


More information about the Petal mailing list