Previous Chapter | Up | Next Section | Contents

Multiple assignments with the let Tag


The #let tag works like the #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 let tag is a new tag that lets you create blocks like:

<!--#in "1,2,3,4"-->

<!--#let num=sequence-item

index=sequence-index

result="num*index"-->

<!--#var num--> * <!--#var index--> = <!--#var result-->

<!--#/let-->

<!--#/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 let expression.

The syntax of the let tag requires that each argument to be evalulated in the head of the 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 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 <!--#let--> block.

Previous Chapter | Up | Next Section | Contents