Hi, I try to use Formulator a little bit more effective to enhance the my code with metal. Currently I do the following: <th> <span tal:replace="structure python:form.item_a.get_value('title')">item_a</span> </th> <td tal:define="item_a request/item_a|nothing"> <input tal:replace="structure python:form.item_a.render(item_a)"> </td> <th> <span tal:replace="structure python:form.item_b.get_value('title')">item_b</span> </th> <td tal:define="item_b request/item_b|nothing"> <input tal:replace="structure python:form.item_b.render(item_b)"> </td> ... I would like to find a clever METAL macro which enables me to use <div metal:use-macro="here/form_zpt/macros/item_macro/item_a">Item A</div> <div metal:use-macro="here/form_zpt/macros/item_macro/item_b">Item B</div> ... Unfortunately I have no idea this is possible at all because I have to handle different objects with just the same naming convention: form.item_a item_a (Variable to define) request/item_a Any hint whether my intent makes sense or if this is a stupid idea? Kind regards Andreas.
Andreas Tille wrote at 2003-9-25 11:43 +0200:
I try to use Formulator a little bit more effective to enhance the my code with metal. Currently I do the following:
<th> <span tal:replace="structure python:form.item_a.get_value('title')">item_a</span> </th> <td tal:define="item_a request/item_a|nothing"> <input tal:replace="structure python:form.item_a.render(item_a)"> </td>
<th>
<tal:attributes define="item string:item_a"> <metal:macro define-macro="ItemControl"> <th tal:define="FormItem form/?item"> <span tal:replace="structure python:FormItem.get_value('title')">Item</span> </th> <td tal:define="ItemValue request/?item | nothing" <input tal:replace="structure python:FormItem.render(ItemValue)"> </td> </metal:macro> </tal:attributes> <tal:attributes define="item string:item_b"> <metal:macro use-macro="template/macros/ItemControl" /> </tal:attributes> ... Dieter
On Thu, 25 Sep 2003, Dieter Maurer wrote:
Currently I do the following:
<th> <span tal:replace="structure python:form.item_a.get_value('title')">item_a</span> </th> <td tal:define="item_a request/item_a|nothing"> <input tal:replace="structure python:form.item_a.render(item_a)"> </td>
<th>
<tal:attributes define="item string:item_a"> <metal:macro define-macro="ItemControl"> <th tal:define="FormItem form/?item"> <span tal:replace="structure python:FormItem.get_value('title')">Item</span> </th> <td tal:define="ItemValue request/?item | nothing" > <input tal:replace="structure python:FormItem.render(ItemValue)"> </td> </metal:macro> </tal:attributes>
<tal:attributes define="item string:item_b"> <metal:macro use-macro="template/macros/ItemControl" /> </tal:attributes> Thanks for this promissing code, but unfortunately it does not really work. Besides the synt6actical typo marked above I get the following error (copied from /error.log):
Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Shared.DC.Scripts.Bindings, line 252, in __call__ Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec Module Products.PageTemplates.ZopePageTemplate, line 228, in _exec Module Products.PageTemplates.PageTemplate, line 95, in pt_render - <ZopePageTemplate at /Test/adr-Formulator/search.html> Module TAL.TALInterpreter, line 200, in __call__ Module TAL.TALInterpreter, line 244, in interpret Module TAL.TALInterpreter, line 703, in do_useMacro Module TAL.TALInterpreter, line 244, in interpret Module TAL.TALInterpreter, line 414, in do_optTag_tal Module TAL.TALInterpreter, line 399, in do_optTag Module TAL.TALInterpreter, line 394, in no_tag Module TAL.TALInterpreter, line 244, in interpret Module TAL.TALInterpreter, line 682, in do_defineMacro Module TAL.TALInterpreter, line 244, in interpret Module TAL.TALInterpreter, line 414, in do_optTag_tal Module TAL.TALInterpreter, line 399, in do_optTag Module TAL.TALInterpreter, line 394, in no_tag Module TAL.TALInterpreter, line 244, in interpret Module TAL.TALInterpreter, line 592, in do_insertStructure_tal Module Products.PageTemplates.TALES, line 217, in evaluate - URL: /Test/adr-Formulator/form_zpt - Line 11, Column 6 - Expression: <PythonExpr FormItem.render(ItemValue)> - Names: {'container': <Folder instance at 9217e80>, 'default': <Products.PageTemplates.TALES.Default instance at 0x86c364c>, 'here': <Folder instance at 9217e80>, 'loop': <SafeMapping instance at 917b478>, 'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 0x86bf3e4>, 'nothing': None, 'options': {'args': ()}, 'repeat': <SafeMapping instance at 917b478>, 'request': <HTTPRequest, URL=http://wr-linux02.rki.ivbb.bund.de:9673/Test/adr-Formulator/search.html>, 'root': <Application instance at 91e26b8>, 'template': <ZopePageTemplate at /Test/adr-Formulator/search.html>, 'traverse_subpath': [], 'user': tillea} Module Products.PageTemplates.ZRPythonExpr, line 48, in __call__ - __traceback_info__: FormItem.render(ItemValue) Module Python expression "FormItem.render(ItemValue)", line 2, in f NameError: global name 'FormItem' is not defined Thanks for the help anyway Andreas.
Andreas Tille wrote at 2003-9-26 14:33 +0200:
On Thu, 25 Sep 2003, Dieter Maurer wrote: ...
<tal:attributes define="item string:item_a"> <metal:macro define-macro="ItemControl"> <th tal:define="FormItem form/?item"> <span tal:replace="structure python:FormItem.get_value('title')">Item</span> </th> <td tal:define="ItemValue request/?item | nothing" > <input tal:replace="structure python:FormItem.render(ItemValue)"> </td> </metal:macro> </tal:attributes> ... Module Python expression "FormItem.render(ItemValue)", line 2, in f NameError: global name 'FormItem' is not defined
Move the "FormItem" definition up from the "th" element to the "metal:macro" element such that it covers both the "th" and "td" elements. Dieter
participants (2)
-
Andreas Tille -
Dieter Maurer