[ZPT] eliminated path expressions .. again

Evan Simpson evan@digicool.com
Mon, 4 Jun 2001 13:57:30 -0400


From: <jmr@computing.com>
> <span tal:define="is_auth python:((user.getUserName() == 'Anonymous User')
and 'unauth') or 'auth'"
>
metal:use-macro="python:path('here/standard_fragments/macros/%s_header' %
is_auth)">
> </span>

Yoinks!  This could be handled by added "metal:define", I suppose, but is
probably better handled by a macro control Script:

<span metal:use-macro="here/standard_header_control"></span>

## Script (Python) "standard_header_control"
##bind context=here
##bind namespace=ns
##parameters=
##
sfm = here.standard_fragments.macros
if ns.SecurityGetUser().getUserName() == 'Anonymous':
  return sfm['unauth_header']
return sfm['auth_header']

or perhaps:

## Script (Python) "standard_header_control"
##bind context=here
##bind namespace=ns
##parameters=
##
if ns.SecurityGetUser().getUserName() == 'Anonymous':
  d = here.unauth_templates
else:
  d = here.auth_templates
return d.standard_fragments.macros['header']

In your particular case, you might be able to create two master templates,
one for authorized and one for unauthorized users.  Set the View permission
for the authorized template to require some role that only authorized users
would have, then use:

<span metal:use-macro="here/auth_standard_fragments/macros/header |
here/unauth_standard_fragments/macros/header"></span>

Cheers,

Evan @ digicool