[Zope] Re: squirting variable definitions into macros using fill-slot

Evan Simpson evan@4-am.com
Wed, 05 Mar 2003 13:21:21 -0600


Felix Ulrich-Oltean wrote:
> I have a macro
...
> I will be using it several times from the same template.  I want to be
> able to pass in values for chosen_thing and the_name, but I can't
> think how.

You can do this as follows:

<!-- macro def -->
<div tal:define="chosen_thing request/chosen_thing|here/chosen_thing;
                  the_name     request/the_name|here/the_name">
<metal:block define-macro="conf_form">
     <input type="radio"
            tal:attributes="name the_name;
                            checked python:chosen_thing=='a' or nothing;"
            value="a" /> a <br />
     <input type="radio"
            tal:attributes="name the_name;
                            checked python:chosen_thing=='b' or nothing;"
            value="b" /> b <br />
</metal:block>

<!-- macro use -->
<div tal:define="chosen_thing some_value;
                  the_name     some_other_value">
<metal:block use-macro="template/macros/conf_form">
</div>

If you wanted to look in 'request' and 'here' if the template doesn't 
supply the value, put the <div> back inside the macro definition, but 
change the defines to 'the_name | request/the_name | here/the_name'.

Cheers,

Evan @ 4-am