[Zope] How to read raw data from HTMLFile?
Martijn Pieters
mj@digicool.com
Thu, 10 Aug 2000 10:28:05 +0200
On Wed, Aug 09, 2000 at 07:49:31PM -0300, Kevin Howe wrote:
> I would like to pre-process a DTML file (accessed using HTMLFile) before
> displaying it in the web browser.
>
> Example Code:
>
> dtml=HTMLFile('manage/mycode', globals())
>
> def cleanUp:
> # eliminate blank lines and <!-- comments--> from DTML
> .....
>
> def printDTML(self):
> return self.cleanUp(dtml)
>
> The problem is that the dtml variable doesn't return the DTML, but the
> object reference. Is there a way to fetch the raw DTML content from the
> HTMLFile object?
Have you looked through the HTMLFile code? You'll see that it subclasses from
several other base classes. One of these is
DocumentTemplate.DT_String.FileMixin, which defines a read_raw method that'll
return the current raw sourcecode of the object.
Your code becomes:
dtml=HTMLFile('manage/mycode', globals())
def cleanUp(source):
# eliminate blank lines and <!-- comments--> from DTML
.....
def printDTML(self):
return self.cleanUp(dtml.read_raw())
--
Martijn Pieters
| Software Engineer mailto:mj@digicool.com
| Digital Creations http://www.digicool.com/
| Creators of Zope http://www.zope.org/
| ZopeStudio: http://www.zope.org/Products/ZopeStudio
-----------------------------------------------------