[ZDP] Some Zope tutorial text

Craig Allen cba@mediaone.net
Tue, 11 May 1999 23:11:54 -0400


I don't know what we are doing with bits and pieces like this, it doesn't really
fit into the FAQ.  But I would sure like to see more of such tutorial text
available.  Let me know if you want more like it, a different form, or
whatever.  And thanks to Pavlos and many others for guidance and feedback.

- Craig
------------------------------------

1. A DTML Method to display a list of links to all the DTML Documents in the
current folder

This is a barebones method that will make a list of links to all the documents
in the current folder.  You can embed a reference to the method or the code
below in a DTML Document.  Because this is a DTML Method, the expression in the
first line ("PARENTS[0]") sets the namespace (or context) to the folder that the
document is contained in.

<!--#with "PARENTS[0]"-->   
    <!--#in expr="objectValues(['DTML Document'])"-->
        <a href="<!--#var id-->"><!--#var title--></a><br>
    <!--#/in--><br>
<!--#/with-->

2.  The same list, sorted by document title

By default, Zope presents the documents sorted by id.  The code below sorts by
document title.

<!--#with "PARENTS[0]"-->   
    <!--#in expr="objectValues(['DTML Document'])" sort=title-->
        <a href="<!--#var id-->"><!--#var title--></a><br>
    <!--#/in--><br>
<!--#/with-->

3.  The same list, sorted in an arbitrary sequence

In order for the code below to work at all, you must create a property called
my_seq for each DTML document.  If you create the properties as integer, you can
assign numbers arbitrarily, e.g.  10, 20, 30, etc.  Leaving gaps in the sequence
makes it easier to rearrange and insert without modifying each document later
on.  Note that if any DTML Document does not have the my_seq property, you will
get an error.

<!--#with "PARENTS[0]"-->   
    <!--#in expr="objectValues(['DTML Document'])" sort=my_seq-->
        <a href="<!--#var id-->"><!--#var title--></a><br>
    <!--#/in--><br>
<!--#/with-->

4.  Suppressing the listing of certain documents

If you have some DTML documents that you don't want listed in the list, use the
code below and assign a value of 0 to the my_seq property in that document.

<!--#with "PARENTS[0]"-->   
  <!--#in expr="objectValues(['DTML Document'])" sort=my_seq-->
    <!--#unless "my_seq==0"-->
      <a href="<!--#var id-->"><!--#var title--></a><br>
    <!--#/unless-->
  <!--#/in--><br>
<!--#/with-->

5.  Adding graphics

There are many ways to reference your image objects in Zope.  The code below
will work if the images (called folderimg and bluedot) are in the current folder
or above it in the object hierarchy, and is the simplest way to include images
on your pages.

<!--#with "PARENTS[0]"-->
  <!--#var folderimg--><A HREF="index_html"><b> In this folder...</b></A><br>
  <!--#in expr="objectValues(['DTML Document'])" sort=my_seq-->
    <!--#unless "my_seq==0"-->
      <!--#var bluedot--><a href="<!--#var id-->"><!--#var title--></a><br>
    <!--#/unless-->
  <!--#/in--><br>
<!--#/with-->

6.  Making the current document plain text in the list

If you want to display the name of the current document NOT as a link (there's
no good reason to have a recursive link here), the code below will add that
enhancement.  Note that it calls for another image, greenstar.

<!--#with "_.namespace(thisdoc=id())"-->
  <!--#with "PARENTS[0]"-->
    <!--#var folderimg--><A HREF="index_html"><b> In this folder...</b></A><br>
    <!--#in expr="objectValues(['DTML Document'])" sort=my_seq-->
      <!--#unless "my_seq==0"-->
        <!--#if "thisdoc == id()"-->
          <!--#var bluedot--><a href="<!--#var id-->"><!--#var title--></a>
        <!--#else-->
          <!--#var greenstar--><b><!--#var title--></b>
        <!--#/if--><br>
      <!--#/unless-->
    <!--#/in--><br>
  <!--#/with-->
<!--#/with-->

7.  Suppressing the entire list if there's only one document in the folder

The code below will print nothing if there is only one DTML document in the
current folder.  Unfortunately, it will print the initial line ("In this
folder...") even if there are two or more documents, if each has the my_seq
property set to 0.

<!--#with "_.namespace(thisdoc=id())"-->
  <!--#with "PARENTS[0]"-->
    <!--#if "_.len(objectIds(['DTML Document'])) > 1"-->
      <!--#var folderimg--><A HREF="index_html"><b> In this
folder...</b></A><br>
      <!--#in expr="objectValues(['DTML Document'])" sort=my_seq-->
        <!--#unless "my_seq==0"-->
          <!--#if "thisdoc == id()"-->
            <!--#var bluedot--><a href="<!--#var id-->"><!--#var title--></a>
          <!--#else-->
            <!--#var greenstar--><b><!--#var title--></b>
          <!--#/if--><br>
        <!--#/unless-->
      <!--#/in--><br>
    <!--#/if-->
  <!--#/with-->
<!--#/with-->

-- 
Craig Allen  - Managing Partner - Mutual Alchemy
Information Architecture - http://alchemy.nu