[Tutor] #include in DocumentTemplate?

Michael P. Reilly arcege@speakeasy.net
Thu, 3 May 2001 11:55:04 -0400 (EDT)


Lance E Sloan wrote
> 
> 
> One of the things that frustrates me about learning Python is the lack
> of documentation.  At least, what I want to know isn't documented or
> it's hard to find.  Perhaps the reason it's so hard to find is that
> such a feature doesn't exist yet.
> 
> As I mentioned in one of my previous messages, I've copied the
> DocumentTemplate module out of Zope to use with some CGIs that I'm
> writing.  It works well and I like it, but I'd like to have one DTML
> file include another rather than having my program parse several of
> them in a row.

This isn't a Zope list, there is one there where you can probably get
a much better answer.

There's plenty of documentation on Zope and its components; have you
looked at <URL: http://www.zope.org/Documentation>?

> Right now, I have code that looks like this:
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/header.dtml')
> ^Iprint tmpl(title = 'Specify Your Unvailability Date')
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml')
> ^Iprint tmpl(mapping = vars())
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/footer.dtml')
> ^Iprint tmpl(year = year)
> 
> What I'd like my code to look like is:
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml')
> ^Iprint tmpl(mapping = vars())
> 
> (Just assume I'm doing the right thing with the arguments to tmpl().)
> And unavailcal.dtml would have something like this:
> 
> ^I<!--#include header.dtml -->
> 
> ^I[body stuff here]
> 
> ^I<!--#include footer.dtml -->
> 
> Is this possible?  I've tried it and it doesn't seem to work.  Would I
> have to write a new DTML tag/function to do this for me?  Has anybody
> already done this?

I'd say, off hand, that DTML is not going to process standard server-side
includes.  That would be up to whatever server you have that handles them.
But me-thinks that it would definately be after the DTML is processes
by Python.

The DT_HTML.HTML class will handle some of its own server-side includes.
It may be that you are to make a subclass to make your own handling
of these.

I don't know how many ppl here are Zope-ites; it might be better for you
to repost your question on the zope mailing list <URL: mailto:zope@zope.org>
there is also an IRC channel (according to the website): #zope on the
server irc.zope.net:6667 (seemingly an Open Source IRC network, there is
even a #python channel).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |