Sometimes you may want to hold onto some value for use later on in the same template. You can do this by storing the value in a local variable. Here is a simple example where a sum is stored in a variable and later printed out:
The WITH= operator is another one that can contain expressions. Within any of those expressions, the variable given as the variable argument will refer to the value given as the value argument. So when we get to the expressionSum () TITLE "Lucky" BODY WITH= variable x value 2 + 5 TEXT x
it will print 7.TEXT x
A variable can have anything as its value, even an image. Here is a template that solves a common problem: how to make page elements the same width:
It generates a page containing a centered image of the word "Hello" rendered in 60-point Helvetica, and beneath it a horizontal rule exactly the same width.Lineup ()TITLE "Underscored Greeting" BODY WITH= variable im value RENDER text "Hello" font-size 60 CENTER IMAGE source im LINEBREAK HRULE width WIDTH im
There are three new operators here. CENTER causes everything generated by the expressions it contains to be centered; HRULE generates a horizontal rule; and WIDTH returns the width of its argument.
Because we put the image in the local variable im instead
of making the RENDER expression simply be the source
argument of IMAGE, we can still find the width of the image
after it has been inserted in the page.