Commit 6b06cd66 authored by Evan Simpson's avatar Evan Simpson

Fix repeat variable

parent 1b45e39a
......@@ -89,7 +89,7 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, Python string literals, and paths.
"""
__version__='$Revision: 1.6 $'[11:-2]
__version__='$Revision: 1.7 $'[11:-2]
import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE
......@@ -167,6 +167,9 @@ class PathExpr:
ob = var[base]
else:
ob = contexts[base]
# Work around lack of security declaration
if path and (ob is contexts['repeat']):
ob = ob[path.pop(0)]
ob = restrictedTraverse(ob, path)
except (AttributeError, KeyError):
if self._name == 'exists':
......
......@@ -87,7 +87,7 @@
An implementation of a generic TALES engine
"""
__version__='$Revision: 1.4 $'[11:-2]
__version__='$Revision: 1.5 $'[11:-2]
import re, sys
from MultiMapping import MultiMapping
......@@ -209,7 +209,7 @@ class Context:
# Keep track of what contexts get pushed as each scope begins.
self._ctxts_pushed = []
# These contexts will need to be pushed.
self._current_ctxts = {'local': 1, 'loop': 1}
self._current_ctxts = {'local': 1, 'repeat': 1}
contexts['local'] = lv = MultiMapping()
init_local = contexts.get('local', None)
......@@ -218,7 +218,8 @@ class Context:
contexts['global'] = gv = contexts.copy()
gv['standard'] = contexts
contexts['var'] = MultiMapping(gv, lv)
contexts['loop'] = MultiMapping()
contexts['repeat'] = rep = MultiMapping()
contexts['loop'] = rep # alias
def beginScope(self):
oldctxts = self._current_ctxts
......@@ -246,7 +247,7 @@ class Context:
def setRepeat(self, name, expr):
expr = self.evaluate(expr)
it = self._engine.Iterator(name, expr, self)
self._current_ctxts['loop'][name] = it
self._current_ctxts['repeat'][name] = it
return it
def evaluate(self, expression):
......
......@@ -6,8 +6,9 @@
<p>Choose your type:</p>
<ul>
<li tal:repeat="type python:'digital', 'analog', 'organic'">
<a href="dummy" tal:attributes="href string:/mach/$type"
tal:content="type">selection</a>
<a href="dummy" tal:attributes="href string:/mach/$type">
<span tal:replace="repeat/type/number">1</span>.
<span tal:replace="type">selection</span></a>
</li>
</ul>
</body>
......
......@@ -6,13 +6,19 @@
<p>Choose your type:</p>
<ul>
<li>
<a href="/mach/digital">digital</a>
<a href="/mach/digital">
1.
digital</a>
</li>
<li>
<a href="/mach/analog">analog</a>
<a href="/mach/analog">
2.
analog</a>
</li>
<li>
<a href="/mach/organic">organic</a>
<a href="/mach/organic">
3.
organic</a>
</li>
</ul>
</body>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment