[ZCM] [ZC] 358/ 1 Request "dtml-in and namespace control"

Collector: Zope Bugs, Features, and Patches ... zope-coders@zope.org
Mon, 22 Apr 2002 07:47:34 -0400


Issue #358 Update (Request) "dtml-in and namespace control"
 Status Accepted, Zope/bug+solution medium
To followup, visit:
  http://collector.zope.org/Zope/358

==============================================================
= Request - Entry #1 by htrd on Apr 22, 2002 7:47 am

 Status: Pending => Accepted

 Supporters added: htrd

dtml-in normally pushes sequence-item onto the namespace stack. This makes it difficult to write bug-free code that has to iterate over objects which have an uncontrolled namespace.

For example, this dtml is intended to produce an index of a folder, but it can be 'broken' if one of the objects in the sequence defines a folder_title attribute.

<dtml-let folder_title=title>
 <dtml-in objectValues>
  <dtml-var title> is in the folder 
         <dtml-var folder_title>
 </dtml-in>
</dtml-let>

This breakage is fundamental to the current dtml-in implementation. it always pushes sequence-item onto the namespace stack, therefore there is no way to reliably access names from the outer namespace from inside the iteration. The iteration is at the mercy of everyone who can add attributes to the elements of the sequence.

I have experimented with several nasty workarounds for this; I propose adding the least-nasty to Zope 2.6. The patch and unit test are in the toby-dtml-in-namespace-branch in CVS; I will prepare documentation changes too.

This change adds a new optional parameter to the dtml-in tag, no_push_items. If present, this tag inhibits the pushing of the object onto the dtml namespace stack. The previous dtml example can be written safely, as:

<dtml-in objectValues no_push_item>
 <dtml-with sequence-item>
  <dtml-var title> is in the folder
 </dtml-with>
 <dtml-var title>
</dtml-in>

==============================================================