[Zope] How to get the DTML code from a document/method?

Rob Page rob.page@digicool.com
Wed, 7 Apr 1999 10:09:19 -0400


Hi Gilles:

>  I want to make prints of my document/method DTML code(the 
>  edit textarea is
>  to small), how can I get it from inside DTML?

Strange I _just_ answered this for a customer!  Here you go:

This is implemented as a Python External Method.  I've pasted the source
code below:

Python source  -->  import string
Python source  -->  
Python source  -->  def view_source(self,path):
Python source  -->          "view the source of a Document"
Python source  -->          id=string.split(path,"/")[-1]
Python source  -->          if not id: id="index_html"
Python source  -->          if not id in self.documentIds():
Python source  -->                  id="index_html"
Python source  -->          doc=getattr(self,id)
Python source  -->          return doc.read_raw()
Python source  -->          return id

This gets called from a dtml_source document whose contents (strangely
enough!) can be seen at:

http://www.zope.org/dtml_source?path=/dtml_source

[Man, I think that's cool!!!]

Then, on any document you can use something like:

http://www.zope.org/dtml_source?path=/

--Rob Page