You can also format variable values with DTML's numerous formatting attributes. Consider the following DTML Document, which contains a simple HTML form.
<form action="FormatForm" method="post">
type="hidden" name="someString" value="the cow jumped over a hunk
of green cheese,
and a pink frog turned into a hummingbird"> <input
value="Hit Me!"> </form> </body> </html>
Once this form is submitted (to another DTML Document instance named "FormatForm"), the form variables and their values become available within the Zope namespace. Here's what FormatForm looks like:
<head></head><body>Look how big I am:<br><dtml-var someString upper>.<p>Don't cut me off when I'm talking:<br><dtml-var someString size="14" etc="..."><p></body></html>
It isn't very hard to guess what this script does:
The <dtml-var> tag comes with a bunch of attributes designed to format the data within it. Here are the important ones:
capitalize - uppercases the first character of the variable;
upper - uppercases the entire variable;
lower - lowercases the variable;
size - restricts the number of characters of the variable that are displayed;
etc - displays a string following the variable.
You can also format the display of the DTML variables using "structured text", which, according to http://www.Zope.org/Members/millejoh/structuredText, is "...text that uses indentation and simple symbology to indicate the structure of a document". Or, in other words, structured text is a set of predefined rules that Zope understands and can use to automatically format your document for you.
In order to see how this works, add the following line of code to the form above,
<input type="hidden" name="someOtherString" value='"Liked this? Send me mail", mailto:firstname.lastname@example.org'>
and the following line to the form processor:
<dtml-var someOtherString fmt="structured-text">
Here's what the revised output looks like:
As you can see, Zope uses its structured text rulesets to automatically hyperlink the text string to the email address specified.
In the meanwhile, I'm out of here. But fear not - your journey into the wild and wacky world that is DTML has just begun, and I will be back with more next week, complete with maps and lollipops. See you then!
Note: All examples in this article have been tested on Linux/i586 with Zope 2.5.0. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!