[ZPT] Some Macros Questions/Suggestions
Tony McDonald
tony.mcdonald@ncl.ac.uk
Mon, 04 Mar 2002 13:25:48 +0000
On 4/3/02 11:55 am, "Chris Withers" <chrisw@nipltd.com> wrote:
> Hi,
>
> Coupla questions relating to METAL macros.
>
> 1. Can I dynamically compute which template I get my macros from?
>
> Something like the following would be cool if it worked:
>
> <html metal:use-macro="python path('here/somemethod')+'/macros/main'"
> <body metal:fill-slot="body>
> ###
> Some specific rendering here
> ###
> </body>
> </html>
>
I'm using this *excellent* snippet from ZopeLabs by PeterBe
(http://www.zopelabs.com/cookbook/1014285275)
<!-- The "default" and simple way -->
<html metal:use-macro="here/standard_masterlook/macros/standard">
<!-- A centralized metal macro -->
<html metal:use-macro="here/getHeader">
#
# The getHeader() Python Script method object
#
return context.standard_masterlook.macros['standard']
#
# Suppose you want to improve getHeader()
#
if somecookie == 'textmode':
return context.standard_masterlook_text.macros['standard']
else:
return context.standard_masterlook.macros['standard']
My own version does this...
request = container.REQUEST
RESPONSE = request.RESPONSE
try:
cookies = request.cookies
useme = cookies['macroTemplate']
except:
useme = 'fancy'
if useme == 'master':
return context.mymacros.macros['master']
else:
return context.standard_look.macros[useme]
Ie it gets the macro expansion you want *based on the value of a cookie* and
from the macro template you want. Veeery cool. I'm using it to supply a
bog-standard page or one with some CSS or one with CSS2 constructs.
Tone
--
Dr Tony McDonald, Assistant Director, FMCC, http://www.fmcc.org.uk/
The Medical School, Newcastle University Tel: +44 191 243 6140
A Zope list for UK HE/FE http://www.fmcc.org.uk/mailman/listinfo/zope