You are not logged in Log in Join
You are here: Home » Members » Pam » Getting Started With DTML Scripting

Log in
Name

Password

 

Getting Started With DTML Scripting

WHAT IS DTML?

DTML is the markup language used by Zope web application. The DTML acronym stands for Document Template Markup Language. DTML is used for generating textual information to be used in your Zope application. Within Zope, DTML is used primarily to generate HTML objects and can also be used to generate SQL commands.

WHERE IS DTML Used?

DTML scripting is used in DTML documents and DTML methods. The basic difference between the DTML documents and methods are properties. DTML Documents are used to hold content and they can have properties. DTML Methods are used to carry out actions and they acquire their properties from the object they belong to. For a more detailed information DTML Methods vs. DTML Documents How To explained the whys of DTML methods and DTML documents.

HOW TO Script With DTML?

The basic DTML script is very similar to HTML and Python tags. Let's start with two examples of the DTML tags that are available with Zope.
<dtml-var standard_html_header>

<dtml-var standard_html_footer>

As you can see, the syntax of the tag is <dtml-somekindoftag> and </dtml-somekindoftag>. Some of the tags are singular and some require duplex tags to denote beginning and ending. In the standard html header and footer tags above, Zope allows you to create the content of the header/footer so that it can be used automatically through out the web site. The standard_html_header and standard_html_footer are themselves DTML documents.

Okay, that is clear as mud. Now, you want to see an example of a DTML script and what it does. For those who like to jump into code directly, the Zope DMTL Reference is available on line at http://www.zope.org/Documentation/Guides/DTML. But, we will go through an example, step by step to clear away the mud.



    <HTML>
    <HEAD>
    <TITLE><dtml-var title_or_id></TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">
    <TABLE WIDTH="100%" BORDER=0>
    <TR>
    <TD><dtml-var logo></TD>
    <TD WIDTH=16>&nbsp;</TD>
    <TD><dtml-var title_or_id>
    </TD>
    <TR>
    <TD COLSPAN=3>&nbsp;</TD>
    </TD>
    <TR>
    <TD><dtml-if sidebar>
    <dtml-var sidebar>
    </dtml-if sidebar>
    </TD>
    <TD><&nbsp;</TD>
    <TD>

You will notice in the example, the DTML scripting is used to place the objects title, logo and sidebar into the HTML document. These objects can be full DTML documents or methods. For example, the sidebar DTML Method list the latest news items along the side of the web page being shown. The logo is a simple image file and the title_or_id will return the title or id of the object.

Similarily, you can replace the standard footer with the following example.



    </TD>
    </TR>
    <TR&;gt;
    <TD>&nbsp;</TD>
    <TD>&nbsp;</TD>
    <TD>
    <dtml-if copyright>
    <P ALIGN="CENTER"><dtml-var copyright></P>
    </dtml-if></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

By replacing this DTML script for the standard_html_footer DTML document, the web pages will have the copyright object displayed with each page. Notice that the <dtml-if> and </dtml-if> DTML tags are duplex. The DTML tags are explained in detail in the Zope DTML Reference.


Where Does This Lead?

This How-To leads to the variety of information available about DTML, a powerful language. This how-to can only be a starting off point. The links below will give you more information about the dynamics of DTML "Document Template Markup Language".