Previous Chapter | Next Chapter | Up | Next Section | Contents

Multiple assignments with the dtml-let Tag


The dtml-let tag works like the dtml-with tag. It is more flexible in that it allows you to make multiple assignments; and allows you to chain assignments, using earlier declarations in later assignments.

The dtml-let tag is a new tag that lets you create blocks like:

<dtml-in "1,2,3,4">

<dtml-let num=sequence-item

index=sequence-index

result="num*index">

<dtml-var num> * <dtml-var index> = <dtml-var result>

</dtml-let>

</dtml-in>

Which yields:

1 * 0 = 0

2 * 1 = 2

3 * 2 = 6

4 * 3 = 12

 

Notice in the above example, the 'result' variable is based on 'num', and 'index', both of which are assigned in the same dtml-let expression.

The syntax of the dtml-let tag requires that each argument to be evaluated in the head of the dtml-let tag must be separated by a newline. Enclosing an argument in double quotes causes it to be evaluated by the DTML expression machinery ("num*index"). Unquoted arguments are referenced by name.

Evaluation of the dtml-let tag is in sequence. The results of earlier assignments are available in later assignments. Later assignments can also override earlier ones, which can be helpful for longer step-by-step calculations. The variables set are in effect for the life of the dtml-let block.

Previous Chapter | Next Chapter | Up | Next Section | Contents