[Zope] [ZGotW] Issue #5 (Closed)

Zope Guru of the Week ZGotW@palladion.com
Sat, 26 Feb 2000 09:54:47 US/Pacific


The current issue of "Zope Guru of the Week" has closed:

===================================================================
Issue #5 -- Rendering DTML in Properties
===================================================================

       Status:  Closed 

    Zen Level:  Disciple (3/8)

     Keywords:  DTML ZClasses 

 Submitted by:  Chuck Burdick chuck.burdick@tradingtechnologies.com
-------------------------------------------------------------------
This problem occurs when you try to make a DTMLDocument-ish ZClass.

1. Suppose you have created a ZClass that you call 'myClass'.

1. Give 'myClass' a property sheet called 'properties'.

1. Create a text property called 'content' on 'properties'.

1. Create a view to edit 'properties'.

1. Create an instance of 'myClass'.

Q: If you put dtml tags in 'content', how can you render the object and
interpret the tags?

For example, suppose you created 'index_html' as a DTMLMethod in 'myClass'
as::

  <dtml-var standard_html_header>
  <dtml-var content>
  <dtml-var standard_html_footer>

This will not work.  It will display the text value of 'content' but the
dtml tags will not have been evaluated.  This is a problem I frequently
encounter.  I do not want to create a complicated subclass of the existing
DTMLDocument classes.  Instead, I want a quick-and-dirty ZClass in which
DTML tags are valid.
-------------------------------------------------------------------

  Reviewed by:  Tres Seaver tseaver@palladion.com
-------------------------------------------------------------------
 What, no valiant Zopemeister would step up to the plate? OK,
 here is my take on the problem.

Short Answer

 You can't do this "quick and dirty".

Long Answer

 Standard DTML and Python methods do not have direct access to
 the DTML rendering machinery, which lives in
 $ZOPE_HOME/lib/python/DocumentTemplate/DT_HTML.py and in
 $ZOPE_HOME/lib/python/DocumentTemplate/DT_String.py.  A quick
 scan of those files convinced me completely that I wasn't going
 to replicate it in a Python method or two.

 So how do you accomplish your goal?  The simplest technique
 would be to morph your ZClass so that it inherits from
 ObjectManager -- you can then stash the 'content' field's
 DTML into a DTML Document, say 'content_dtml', contained within
 the instance, and render it from your 'index_html' with the
 exact syntax you specified.  You might even be able to use the
 same user interface as your first cut:  in the form processing
 method, for instance, you could add::

   <dtml-call "content_dtml.manage_upload( content )">

 Another answer involves hacking the dtml-var tag to allow
 for a 'fmt=dtml' parameter, which would then do the recursive
 rendering of the property value.


-------------------------------------------------------------------