[Zope] my solution to #include in DocumentTemplate

Dieter Maurer dieter@handshake.de
Sat, 12 May 2001 15:40:37 +0200 (CEST)


Lance E Sloan writes:
 > ...
 > What I was looking for was
 > something like:
 > 
 > 	<!--#include file="../path/to/filename.dtml" -->
 > 
 > in a DTML file to include another DTML file, recursively.  I
 > ended up doing this:
 > 
 > 	<!--#with "_(incDoc = DocumentTemplate.HTMLFile('../path/to/file.dtml'))"
 > 	-->
 > 	<!--#var expr="incDoc(x = x)" -->
 > 	<!--#/with -->
Interesting that "DocumentTemplate" is exposed this way.

Will hopefully not work inside Zope (potential security risk).

 > It works well.  The only problem is that for every object I want
 > to pass to the included document must be specified individually
 > (x = x).  I tried these but they didn't work:
You should learn about the two (optional) positional arguments
of "DocumentTemplate.HTMLFile.__call__".
One source is the DTML section of

  URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html

If you pass "_" as second parameter:

   <dtml-var expr="incDoc(_.None,_,x=x)">

or simply use

   <dtml-var incDoc>

then your incDoc should have access to the name in the calling
namespace.


Dieter