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

Edward Muller edwardam@interlix.com
06 Mar 2003 23:26:39 -0600


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