Passing args to PageTemplateFile instances
Hi, I have read some posts about this before, but the solutions given there does not seem to work for me. The deal is that I would like to make a product where amongst other things there needs to be a search feature. I then make a method that takes input from a form with searchwords but then I get stuck. How do I get the search results handed over to a ZPT that will display them? I would like to just pass the results as an argument to it, and have made a simple test-product to test how this would work. class TestProd(SimpleItem): """A TestProd object""" meta_type = "TestProd" manage_options = ( {"label": "Edit", "action": "manage_main"}, {"label": "View", "action": "index_html"}) manage_main = PageTemplateFile("templates/mainTestProd", globals()) index_html = PageTemplateFile("templates/indexTestProd", globals()) test = PageTemplateFile("templates/test", globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test.__of__(self)(something="blah") In the template I should now be able to access options/something according to previous posts, but this: <span tal:replace="options/something"/> results in: Error Type: KeyError Error Value: 'something' I am using Zope 2.8.0. Am I doing it wrong? How can it be done correctly? -- Anders -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? ------END GEEK CODE BLOCK------ PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DE...
manage_main = PageTemplateFile("templates/mainTestProd", globals()) index_html = PageTemplateFile("templates/indexTestProd", globals()) test = PageTemplateFile("templates/test", globals())
def __init__(self, id, title): self.id = id self.title = title
def testit(self, REQUEST=None): return self.test.__of__(self)(something="blah")
In the template I should now be able to access options/something according to previous posts, but this:
<span tal:replace="options/something"/>
Why the extra self-wrapping. Do it this way: def testit(self, REQUEST=None): return self.test(self, self.REQUEST, something="blah") Then you'll be able to use: <span tal:replace="options/something"/> -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
participants (2)
-
Anders Bruun Olsen -
Peter Bengtsson