[Zope] Using DTML methods to provide HTML

Anders Qvist quest@valdez.netg.se
Sun, 11 Jul 1999 13:00:15 +0200 (CEST)


In a DTML document called "authors" I have this situation:

  <!--#var "sixfield_page(title='Authors and their works',
                          body=authors_body())"-->

six_fieldpage is a DTML method which uses two parameters, title and body
and returns an entire HTML page. authors_body is a DTML method in the same
folder and looks like this:

  <!--#in get_all_authors-->
    <!--#var "sixfield_textblock(title=last_name + ', ' + first_name, 
                               body=rid)"-->
  <!--#/in-->

When trying to look at authors, I get the following error:

  Error Type: KeyError
  Error Value: get_all_authors

<!--
Traceback (innermost last):
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/ZPublisher/Publish.py, line 256, in publish_module
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/ZPublisher/Publish.py, line 161, in publish
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/ZPublisher/mapply.py, line 154, in mapply
    (Object: authors)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/ZPublisher/Publish.py, line 98, in call_object
    (Object: authors)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/OFS/DTMLDocument.py, line 181, in __call__
    (Object: authors)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/OFS/DTMLDocument.py, line 177, in __call__
    (Object: authors)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/DocumentTemplate/DT_String.py, line 514, in __call__
    (Object: authors)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/DocumentTemplate/DT_With.py, line 133, in render
    (Object: _.namespace(title='Authors and their works', 
                        body=authors_body()))
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/DocumentTemplate/DT_Util.py, line 315, in eval
    (Object: _.namespace(title='Authors and their works', 
                        body=authors_body()))
  File <string>, line 0, in ?
  File  /home/quest/dls/Zope-2.0.0a3-src/lib/python/OFS/DTMLMethod.py, line 152, in __call__
    (Object: authors_body)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/DocumentTemplate/DT_String.py, line 514, in __call__
    (Object: authors_body)
  File /home/quest/dls/Zope-2.0.0a3-src/lib/python/DocumentTemplate/DT_In.py, line 628, in renderwob
    (Object: get_all_authors)
KeyError: (see above)

-->

In Zope/manage things looks like this (to convince you, I have not
misspelled anything):

    /
      /reviews
        authors (Authors and their Work) 
        authors_body (Build author list) 
        authors_body_titles (Build list of all titles by one author) 
        get_all_authors (Retr list of all authors) 
        get_titles_by_author (Retr all titles by one author) 
        index_html (Test) 
        reviews_db_connection (Da DB Connection) 
        sixfield_menu (Sixfield style menu) 
        sixfield_page (Sixfield style Page) 
        sixfield_textblock (Sixfield style Textblock) 

If I understand the error correctly, authors_body is not 'acquired' in
the usual zope sense, but rather executed in a more traditional Python
context. 

This raises two questions:

  1) How do I make this work?
  2) Is this the right way to do things or am I abusing the Zope design?

Anders "Quest" Qvist
NetGuide Scandinavia

-- Why suffer scarcity? Look for the Open Source and enter a world of plenty!