[Zope] Advanced DTML Question

Bill Anderson bill@libc.org
Wed, 01 Mar 2000 19:18:38 -0700


"James W. Howe" wrote:
> 
> I'm trying to write a DTMLMethod which will write out a list of data items
> found from a catalog, sorted in alphabetical order.  This is
> easy.  Basically I do something like this:
> 
> <dtml-in "Catalog(meta_type='foo')" sort=someAttribute>
>      <dtml-with "Catalog.getobject(data_record_id_)">
>          <dtml-var objvar1><dtml-var objvar2> ...
>      </dtml-with>
> </dtml-in>
> 
> I've got this working, no problem.  Now, since the list of these items
> might be somewhat long, I want to build a simple index at the top of the
> page and use page anchors to get to key points on the page. Basically I'm
> going to display the alphabet and when the user clicks on a letter, the
> page should scroll somewhere in the vicinity of an item which starts with
> that letter.  To that end, what I would like to do is have some code inside
> of my dtml-in loop which gets the first letter from the current entry,
> checks to see if an anchor for that letter has been written, if not, a new
> anchor tag is inserted into the stream.  My problem is I don't really know
> how to code this up.  It seems like maybe that at least some of this should
> be done at the Python level but I'm not quite sure how to split up the
> functionality.
> 
> Has anybody done anything similar who would be willing to give me some
> advice as to the best way to go about solving this problem?

My email window dies suddenly, before I could write what I intedned ...
looks like it sent itself waaay too early. Sorry.

Anyway, have you tried the batch processing instructions at
http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.8.5.html
They should give you some insight as to how to get the first letter. You
may then be able to set a temp variable, called CurrentAnchor, for
example, that contains the last letter that was used to set an anchor.
Testing agaimst the CurrentAnchor, you should be able to set (if not the
same), or continue (if the same).

Unfortunately, ZCatalog apparently doesn't do reg-ex searches yet.
Otherwise, I'd say create your links a alink to a page that looked for
thins that started with that letter.

Alternatively, you could look at the howto, and give a range of letter,
say a-e, f-j, etc. and just use the batch processing capabilities in
DTML. :)


Just some ideas.


-- 
In flying I have learned that carelessness and overconfidence are 
usually far more dangerous than deliberately accepted risks. 
          -- Wilbur Wright in a letter to his father, September 1900