[Zope] Newbie: Missing a Variable (TAL/METAL Question)
David H
bluepaul at earthlink.net
Wed Jul 26 18:28:45 EDT 2006
beno - wrote:
> Hi;
> I have the following block of code:
>
> <table tal:define="objects here/objectValues;
> sort_on python:(('title', 'nocase', 'asc'),
> ('bobobase_modification_time',
> 'cmp', 'desc'));
> sorted_objects python:sequence.sort(objects, sort_on);
> start python:getattr(request, 'start', 0);
> batch
> python:modules['ZTUtils'].Batch(sorted_objects, size=10, start=start);
> previous python:batch.previous;
> next python:batch.next">
> <tr tal:repeat="item batch">
> <td tal:content="item/title">title</td>
> <td tal:content="item/bobobase_modification_time">
> modification date</td>
> <td tal:content="here/author">author</td>
> <td tal:content="here/content">content</td>
> </tr>
> </table>
> that works fine. But I'd like to call the following in that table:
>
> <td><tal:content
> metal:use-macro="here/XXX/macros/author"></tal:content></td>
> where "XXX" is the "item" that changes each time a new item from the
> batch is called. In other words, there is a folder with a "batch" of
> files, and each file is an "item". So, since the files' titles are
> simply sequential numbers, it would look something like this:
>
> <td><tal:content
> metal:use-macro="here/1/macros/author"></tal:content></td>
> <td><tal:content
> metal:use-macro="here/2/macros/author"></tal:content></td>
> <td><tal:content
> metal:use-macro="here/3/macros/author"></tal:content></td>
> ...
How do I do that? Even better, is it possible to just open up each file
and read its contents??
> Thanks,
> Ben
>
> ------------------------------------------------------------------------
Ben,
First this is wrong:
<td><tal:content ...
If should be
<td tal:content ...
But that may be wrong in the context you've given.
Since "do it in python" has been a theme lately, you can also return a
macro from a python script like so:
Where there is an author might be a parameter.
#some python script
#
return container.YourMacroFolder.someMacro[ author ]
-----------------------------------------------------------------------
And in your ZPT: (where result.author is just a stub for whatever your
using)
<td><span metal:use-macro="python:
context.youPythonScript(result.author)">macro goes here</span></td>
I suggest *always* doing stuff in python when things are not clear.
Then code back into your Page Templates, if desired
DAvid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20060726/db03c787/attachment.htm
More information about the Zope
mailing list