[ZPT] Re: macros and contexts

Edward Muller edwardam at interlix.com
Fri Sep 12 12:20:26 EDT 2003


On Fri, 2003-09-12 at 10:24, Seb Bacon wrote:
> Seb Bacon wrote:
> > This is kind of difficult to explain, partly because I suspect I am 
> > trying to abuse macros.  I want to use macros to display objects other 
> > than the current context.  So, say I have a macro in a ZPT called 
> > widgetlib:
> > 
> >  <div metal:define-macro="widget_1_view">
> >    I am the widget 1 view on <span tal:replace="here/getId">some
> >    id or other</span>
> >  </div>
> > 
> > And I use it like this:
> > 
> >  <div metal:use-macro="here/widgetlib/macros/widget_1_view">
> >    Widget 1 view goes here
> >  </div>
> > 
> > How can I cause the above macro invocation to use a different value for 
> > 'here'?
> 
> Just to follow up, the solution I have thought of so far is to redefine 
> the value of  'here':
> 
>   <div tal:define="here nocall:here/foo">
>    <div metal:use-macro="here/widgetlib/macros/widget_1_view">
>      Widget 1 view goes here
>    </div>
>   </div>
> 
> Which is pretty nasty, but really seems to be the only solution...?
> 
> seb

Wouldn't you use slots?

<div metal:define-macro="widget_1_view">
  I am the widget 1 view on <span metal:define-slot="content"/>.
</div>

Used like

<div metal:use-macro="here/widgetlib/macros/widget_1_view">
  <span metal:fill-slot="content" tal:replace="here/getId"/>
</div>

Assuming here/getId = "WidgetsForAllPeople"
Produces:

<div>
  I am the widget 1 view on WidgetsForAllPeople.
</div>

Or something similar.

But I'm not really sure what you are trying to do...

-- 
Edward Muller - http://www.interlix.com - "Open Source Specialists"
Dedicated Zope Hosting - Web Hosting - Open Source Consulting
Network & PC Service & Support - Custom Programming
Phone: 417-862-0573 - Cell: 417-844-2435 - Fax: 417-862-0572
Jabber: edwardam at jabber.interlix.com - AIM: edwardam453 - ICQ: 287033
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.zope.org/pipermail/zpt/attachments/20030912/55603d7f/attachment.bin


More information about the ZPT mailing list