[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Creating Basic Zope Applications
webmaster@zope.org
webmaster@zope.org
Sun, 22 Sep 2002 11:41:11 -0400
A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/SimpleExamples.stx#3-57
---------------
Finally let's add the ability to sort this list by file name or by
modification date. Change the *index_html* method again::
<dtml-var standard_html_header>
<h1>File Library</h1>
<table>
<tr>
<th><a href="&dtml-URL0;?sort=name">File</a></th>
<th><a href="&dtml-URL0;?sort=date">Last Modified</a></th>
</tr>
<dtml-if expr="_.has_key('sort') and sort=='date'">
<dtml-in expr="objectValues('File')"
sort="bobobase_modification_time" reverse>
<tr>
<td><a href="&dtml-absolute_url;"><dtml-var title_or_id></a></td>
<td><dtml-var bobobase_modification_time fmt="aCommon"><td>
</tr>
</dtml-in>
<dtml-else>
<dtml-in expr="objectValues('File')" sort="id">
<tr>
<td><a href="&dtml-absolute_url;"><dtml-var title_or_id></a></td>
<td><dtml-var bobobase_modification_time fmt="aCommon"><td>
</tr>
</dtml-in>
</dtml-if>
</table>
<dtml-var standard_html_footer>
% Anonymous User - Aug. 20, 2002 9:34 am:
Could somebody explain to me what that _.has_key()-function does so that I might be able to reuse it in
another application?
% krump - Aug. 27, 2002 1:16 pm:
"has_key('KeyName')" is a normal Python dictionary method. Normally you would create a Python dictionary and
then look to see if it had a particular item in it by using something like:
DictionaryName.has_key('KeyName'). The underscore in front of the method must be something Zopish.
Is the HTML table showing up for everyone else? That is the only part of the "File" index_html DTMLmethod
that is not working for me.
% Anonymous User - Sep. 19, 2002 1:08 am:
In the code above, the td closing tags for bobobase_modification_time are written as <td> when they should be
</td>. That's possibly why you're not seeing the table properly?
% Anonymous User - Sep. 22, 2002 11:41 am:
"_" is the DTML namespace variable where DTML looks up names.
Since the bottom of this namespace contains the REQUEST object
(which again contains, among others, the URL parameters)
this should be better expressed as
<dtml-if expr="REQUEST.has_key('sort') and sort=='date'">
("_['sort']" is not necessarily "REQUEST['sort']")