[Zope] Re: metal:fill-slot and tal:condition
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dragos Chirila wrote: Hi everybody, I am stuck with the following problem. I would appreciate it very much if you could help me with it. So I have a ZPT where a macro is defined with several slots; one of the slots like below: tal:block metal:define-slot=slot_issue SLOT DEFAULT CONTENT /tal:block The common way to put other content in the slot is: tal:block metal:fill-slot=slot_issue CUSTOM SLOT CONTENT /tal:block Now, in a ZPT that uses the above marco I want to replace the default slot content with other stuff *only* if a condition is fulfilled: tal:block tal:condition=condition-code metal:fill-slot=slot_issue CUSTOM SLOT CONTENT /tal:block If the condition-code returns True then the CUSTOM SLOT CONTENT is put instead of the default slot content - correct. If the condition-code returns False then nothing will be displayed - this is not correct?!. I also tried somthing like: tal:block tal:condition=condition-code tal:block metal:fill-slot=slot_issue CUSTOM SLOT CONTENT /tal:block /tal:block In this case the content of the slot is CUSTOM SLOT CONTENT in both cases - the result is True or False. The only solution that I can think of is not elegant at all because I have to duplicate the slot_issue's default content: tal:block metal:fill-slot=slot_issue tal:block tal:condition=condition-code CUSTOM SLOT CONTENT /tal:block tal:block tal:condition=python:not condition-code SLOT DEFAULT CONTENT /tal:block /tal:block Is there other wat to accomplish this? You might modify the macro to allow this, making the default content a separate macro:: html metal:define-macro=slotted body h1 Slotted /h1 div metal:define-slot=slot_issue metal:default metal:define-macro=default_issue DEFAULT SLOT CONTENT metal:default /div /body /html The template which includes the macro would then be:: html metal:use-macro=context/other_template/macros/slotted body div metal:fill-slot=slot_issue tal:block condition=condition-code CUSTOM SLOT CONTENT /tal:block tal:block condition=not:condition-code div metal:use-macro=context/other_template/macros/default_issue/ /tal:block /div /body /html It may help to remember that macros are actually inlined into the including template, rather than being called as a function would be. Tres. - -- === Tres Seaver +1 540-429-0999 [EMAIL PROTECTED] Palladion Software Excellence by Designhttp://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF3YQz+gerLs4ltQ4RAjetAKCpQdrYi6Vl0LeWkAvE6sFVt2RwOACg0GgZ tYguZqyYKbTohGOmh6in5gw= =Q5Bv -END PGP SIGNATURE- ___ 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 )
[Zope] Re: metal:fill-slot and tal:condition
Dragos Chirila schrieb: Hi everybody, I am stuck with the following problem. I would appreciate it very much if you could help me with it. [snip] If I understand correctly you want to fill a slot if a condition is true else leave the default. A typical slot-modell looks something like this: Template I: a metal:define-macro=A b metal:define-slot=B default /b /a Template II: a metal:use-macro=here/TemplateI/macros/A b metal:fill-slot=B custom /b /a A different approach, a use-macro-modell: Template I: a metal:define-macro=A tal:define=macros here/getmacros b metal:use-macro=macros/B/ /a Python Script getmacros: macros = {} # default_macros, custom_macros are page templates. macros.update(container.default_macros.macros) if blah: macros.update(container.custom_macros.macros) return macros This is oversimplified, but I hope it helps you to find a solution. Regards, Tonico ___ 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 )