[ZPT] Using Script to Select Macro

Doug Tillman Doug.Tillman at grainger.com
Wed Aug 4 10:02:25 EDT 2004


Any help or pointers to reference materials would be most appreciated -
I am attempting to use a Python script to return the path to a macro
that I want to use in a given page. I'm passing the 'linktype' argument
when I call the template from a script - hence the 'options/linktype'.
Here's the error I get:

Error Type: NameError
Error Value: name 'linkme' is not defined

<p tal:define="linkme options/linktype"
metal:use-macro="python:here.getNavLinks(linktype=linkme)">test</p>

The Python script simply returns the string path to the macro.  If I
change the metal:use-macro to tal:content then the returned string
appears as text on the page but I can't seem to get the macro to be
included.  This seems straightforward but it isn't working.

When I used this:
<div tal:define="linkme options/linktype">
    <p tal:content="python:here.getNavLinks(linkme)">linktype</p>
- the path returned from the Python script appeared fine - then after a
bit more struggle and testing I started seeing this error from the
markup above:
Error Type: NameError
Error Value: global name 'here' is not defined

Here's the Python script getNavLinks - simple stuff.  

from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE

if (linktype=="User"):
    return "here/navlinks/macros/userlinks"
elif (linktype=="Silo"):
    return "here/navlinks/macros/silolinks"
elif (linktype=="BuildType"):
    return "here/navlinks/macros/buildtypelinks"


Thanks,

Doug


More information about the ZPT mailing list