[Zope3-dev] Number of languages in Zope 3
Tres Seaver
tseaver@zope.com
09 Apr 2003 08:39:43 -0400
On Wed, 2003-04-09 at 06:52, Andy McKay wrote:
> >> But now you want to add a custom title attribute. Just because of this
> >> you have to switch to a completely different syntax:
> >>
> >> <img
> >> tal:replace="structure
> >> python:here.Imagefolder.imagename.tag(title='MyTitle')"
> >> src="" />
> >
> >> This is even hard to get for somebody who knows Python because you are
> >> limited to having to use single quotes in the brackets due to some
> >> limitation of the TAL parser.
> >
> > I'd suggest writing this as a method in a supporting view class.
>
> I don't know much about zope 3 at the moment, but how does writing a
> supporting view class make passing parameters from a template easier?
>
> I think the point here is that the template, contains a value that you
> want to pass to the method. This is common when one does a tal:repeat,
> and then pass some value of that repeat off to a function for each
> iteration.
In Zope3, that idiom would typically be replaced by an intermediate
method on the view class which did the underlying work. E.g., where in
Zope2 I might to something like:
<div tal:repeat="snippet python:here.objectValues(['Some Type'])">
<h3 tal:conetnt="python:snippet.headline(version='Brief')">HEADLINE
>/h3>
<div tal:content="python:snippet.teaseText(maxwords=100)>TEASE</div>
</div>
in Zope3 I would add a method to the view class which did the heavy
lifting:
def getSnippetInfo(self):
results = []
for snippet in [x for x in self.context.values()
if ISnippet.isImplementedBy(x) ]:
results.append({'title' : snppet.headline(version='Brief'),
'tease' : snippet.teaseText(maxWords=100)})
return results
The template then becomes much clearer:
<div tal:repeat="info context/getSnippetInfo">
<h3 tal:content="info/title">TITLE</h3>
<div tal:content="info/tease">TEASE</div>
</div>
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com