calling zpt from a script with options
Hi forgive me if it's trivial, but I'm a complete zope newbie.... I read in the zope book that if I want to call zpt from a script (in my case, to render errors in a form) I do something like this: -- script: pt = context.body_content s = pt(zerror="This is an error") return s zpt: <i tal:content="options/zerror | default">error</i> -- This works without a problem, but it only shows the "body_content" file. this file is part of a layout (inside a folder) and I want to call the folder as the url, so it will acquire the index_html in an upper directory. I tried changing the "pt" variable to context.index_html and calling "here/index_html/options/zerror" in the template but it didn't show. how can I achieve that? thanx -- Haim
Haim Ashkenazi wrote at 2005-1-5 20:55 +0200:
forgive me if it's trivial, but I'm a complete zope newbie....
You must also learn how to formulate questions :-)
... I read in the zope book that if I want to call zpt from a script (in my case, to render errors in a form) I do something like this:
-- script:
pt = context.body_content s = pt(zerror="This is an error") return s
zpt:
<i tal:content="options/zerror | default">error</i> --
This works without a problem, but it only shows the "body_content" file. this file is part of a layout (inside a folder) and I want to call the folder as the url, so it will acquire the index_html in an upper directory.
I do not yet understand what you want... Usually, the overall layout is defined in a macro and individual page templates use this macro and fill slots of it. Maybe, you read about "metal:define-macro", "metal:define-slot", "metal:use-macro" and "metal:fill-slot" in the Zope Book. Otherwise, if you do not want to call "body_content" but "index_html", then you simply use "pt = content.index_html" (provided it is a ZPT, too).
I tried changing the "pt" variable to context.index_html and calling "here/index_html/options/zerror" in the template but it didn't show.
In "index_html", you would access "zerror" also via "option/zerror". When your "index_html" would call "body_content", you would need to pass "zerror" again. -- Dieter
On Thu, 06 Jan 2005 19:47:18 +0100, Dieter Maurer wrote:
Haim Ashkenazi wrote at 2005-1-5 20:55 +0200:
forgive me if it's trivial, but I'm a complete zope newbie....
You must also learn how to formulate questions :-)
... I read in the zope book that if I want to call zpt from a script (in my case, to render errors in a form) I do something like this:
-- script:
pt = context.body_content s = pt(zerror="This is an error") return s
zpt:
<i tal:content="options/zerror | default">error</i> --
This works without a problem, but it only shows the "body_content" file. this file is part of a layout (inside a folder) and I want to call the folder as the url, so it will acquire the index_html in an upper directory.
I do not yet understand what you want...
Usually, the overall layout is defined in a macro and individual page templates use this macro and fill slots of it. Maybe, you read about "metal:define-macro", "metal:define-slot", "metal:use-macro" and "metal:fill-slot" in the Zope Book. thanx, I didn't reach this part yet (I started working with zope 5 days ago), but I'll get to it now...
Otherwise, if you do not want to call "body_content" but "index_html", then you simply use "pt = content.index_html" (provided it is a ZPT, too).
I tried changing the "pt" variable to context.index_html and calling "here/index_html/options/zerror" in the template but it didn't show.
In "index_html", you would access "zerror" also via "option/zerror".
When your "index_html" would call "body_content", you would need to pass "zerror" again.
that's how I solved it eventually: <td tal:define="zerror options/zerror" tal:content="structure python:here.body_content(zerror = zerror)">budy content</td> thanx -- Haim
Haim Ashkenazi wrote:
Hi
forgive me if it's trivial, but I'm a complete zope newbie....
I read in the zope book that if I want to call zpt from a script (in my case, to render errors in a form) I do something like this:
-- script:
pt = context.body_content s = pt(zerror="This is an error") return s
zpt:
<i tal:content="options/zerror | default">error</i> --
This works without a problem, but it only shows the "body_content" file. this file is part of a layout (inside a folder) and I want to call the folder as the url, so it will acquire the index_html in an upper directory.
I tried changing the "pt" variable to context.index_html and calling "here/index_html/options/zerror" in the template but it didn't show.
options are the parameter with the actual template was called with. Therefore here/index_html has not options since it is not called as a method. If I understand your problem correctly, you shoud do something like: script: pt = context.index_html return pt(zerror="This is an error") zpt: <div tal:define"error options/zerror | nothing" > <i tal:content="error" tal:condition="error" /> <div tal:content="structure here/body_content" /> </div> robert
On Thu, 06 Jan 2005 22:54:01 +0100, robert wrote:
Haim Ashkenazi wrote:
Hi
forgive me if it's trivial, but I'm a complete zope newbie....
I read in the zope book that if I want to call zpt from a script (in my case, to render errors in a form) I do something like this:
-- script:
pt = context.body_content s = pt(zerror="This is an error") return s
zpt:
<i tal:content="options/zerror | default">error</i> --
This works without a problem, but it only shows the "body_content" file. this file is part of a layout (inside a folder) and I want to call the folder as the url, so it will acquire the index_html in an upper directory.
I tried changing the "pt" variable to context.index_html and calling "here/index_html/options/zerror" in the template but it didn't show.
options are the parameter with the actual template was called with. Therefore
here/index_html has not options since it is not called as a method. If I understand your problem correctly, you shoud do something like:
script:
pt = context.index_html return pt(zerror="This is an error")
zpt: <div tal:define"error options/zerror | nothing" > <i tal:content="error" tal:condition="error" /> <div tal:content="structure here/body_content" /> </div> If I understand correctly, this will first print the "zerror" variable, and then the content of here/body_content. I want the error to show in the body of the form (inside body_content). anyway, I solved it like this:
<td tal:define="zerror options/zerror" tal:content="structure python:here.body_content(zerror = zerror)"> budy content </td> now I can call index_html from the script and add tal:condition (not shown above) to test for the existence of "options/error" and call body_content like the example above. thanx -- Haim
participants (3)
-
Dieter Maurer -
Haim Ashkenazi -
robert