DTML Basics (part 4) - Call Of The Wild (
Page 7 of 9 )
DTML also offers a way to call other DTML
methods from within your code, via the <dtml-call> construct. This comes in
particularly handy when you want to invoke a method, but aren't really all that
concerned about displaying the results of that method to the user - SQL queries
are a prime example of this.
Consider the following example, which demonstrates:
<dtml-var standard_html_header>
<dtml-call addMovieToCollection>
<h1>Movie
<dtml-var name> has been added to your DVD collection!</h1>
<p><a
href="listMovieCollection">List Movies in your Collection</a></p>
<p><a
href="addMovieForm">Add Movies</a></p>
<dtml-var standard_html_footer>
In this case, I've called the addMovieToCollection() Z-SQL method. This method
adds a record to the table containing my DVD collection. However, since I don't
really need to worry about the return value, I can use the <dtml-call> tag
to invoke the Z-SQL method.
Note also that I am not explicitly passing any parameters to the Z-SQL method.
In this scenario, Zope take cares of extracting the required data from the REQUEST
namespace and passing the parameters to the invoked method automatically. Isn't
that neat?
There is a caveat, though - invoke the same method in an expression, and your
workload increases. Why? Because now it's up to you to pass the parameters to
the method explicitly.