[ZCM] [ZC] 1195/ 4 Comment "tal:define and metal:fill-slot"
Collector: Zope Bugs, Features,
and Patches ...
zope-coders-admin at zope.org
Tue Jan 20 13:33:02 EST 2004
Issue #1195 Update (Comment) "tal:define and metal:fill-slot"
Status Pending, Zope/bug medium
To followup, visit:
http://zope.org/Collectors/Zope/1195
==============================================================
= Comment - Entry #4 by dchandek on Jan 20, 2004 1:32 pm
> I guess this is not a bug, but by design:
> A metal:use-macro replaces the contents of the current
> tag with the contents of the marco;
> it thus swallows the tal:define, too
> (If it would not swallow tal-statements, what would be the
> results of a tal:content statement? ;-)
camil7 is right .... That's not what I expected. Also, the macro's variables are available to the calling template! I guess if you want to define variables for a template that calls a page macro (as in my example), you have to use a <tal:block tal:define="" /> above the macro call. That seems to work.
________________________________________
= Comment - Entry #3 by camil7 on Jan 20, 2004 12:39 pm
I guess this is not a bug, but by design:
A metal:use-macro replaces the contents of the current
tag with the contents of the marco;
it thus swallows the tal:define, too
(If it would not swallow tal-statements, what would be the
results of a tal:content statement? ;-)
________________________________________
= Comment - Entry #2 by dchandek on Jan 20, 2004 11:18 am
Add to version info: PageTemplates-1-4-0
________________________________________
= Request - Entry #1 by dchandek on Jan 20, 2004 11:15 am
Although the ZPT docs say that variables defined with tal:define are available in that tag and any child tags (or with global vars, below that tag in the file), there appears to be a problem with accessing varibles inside metal:fill-slot blocks.
Inside a metal:fill-slot block I can only access variables (either local or global) which have been defined either in that block, or globally in another fill-slot block.
For example, in the CMF context, if I create a page template with this code:
<html metal:use-macro="here/main_template/macros/master"
tal:define="member_name here.portal_membership.getAuthenticatedMember().getUserName()"
>
[...]
<body>
<metal:block fill-slot="header">
<h1 tal:content="member_name" />
</metal:block>
[...]
</body>
</html>
I get a KeyError like this:
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 /015/unpublished_items>
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 726, in do_defineSlot
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 497, in do_insertText_tal
Module Products.PageTemplates.TALES, line 226, in evaluateText
Module Products.PageTemplates.TALES, line 220, in evaluate
[...]
Module Products.PageTemplates.Expressions, line 206, in __call__
Module Products.PageTemplates.Expressions, line 194, in _eval
Module Products.PageTemplates.Expressions, line 146, in _eval
- __traceback_info__: member_name
KeyError: member_name
But if I define the member_name variable as global on another fill-slot block above it in the file, it works OK.
==============================================================
More information about the Zope-Collector-Monitor
mailing list