squirting variable definitions into macros using fill-slot
I have a macro like this: <metal:block define-macro="conf_form"> <div class="something" tal:define="chosen_thing request/chosen_thing|here/chosen_thing; the_name request/the_name|here/the_name"> <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 /> </div> </metal:block> 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. If I define a slot, e.g. for the <div>, the stuff in fill-slot will replace all the stuff in the macro. Alternatively, I could use fill-slot and a 'global' definition, but then I wouldn't be able to use it more than once. Am I just being dumb here? It must be possible to pass in dynamic information using fill-slot. Thanks for any advice, Felix.
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
I'm a moron! I've been wondering how to pass variables to macros for a month now! I use tal:define a bunch when needing to do various large lookups multiple times (state select boxes for instance) ... It just never dawned on me to combine the two! Whack! Whack! Whack! Arg! On Wed, 2003-03-05 at 13:21, Evan Simpson wrote:
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
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Edward Muller
Interlix - President Web Hosting - PC Service & Support Custom Programming - Network Service & Support Phone: 417-862-0573 Cell: 417-844-2435 Fax: 417-862-0572 http://www.interlix.com
participants (3)
-
Edward Muller -
Evan Simpson -
Felix Ulrich-Oltean