Chapter 9 Generation Reference Guide (GTL)


Using macros

Macros can be used to express template logic, and to loop on object collections. Each macro keyword must be preceded by a . (dot) character and has to be the first non blank character of a line. Make sure you also respect the macro syntax in terms of line breaks.

You define a macro inside a template, or a command entry.

You can use three types of macros, as shown in the following table:

Macro Syntax
Block-macro <if> | <vbscript> | <unique> | <lowercase> | <uppercase> | <replace> | <delete> | <block>
Loop-macro <foreach_item> | <foreach_line> | <foreach_part>
Simple-macro <bool> | <set_object> | <set_value> | <execute_vbscript> | <execute_command> | <abort_command> | <change_dir> | <create_path> | <log> | <warning> | <error>

Block macro

Block macros consist of a begin and an end keyword delimiting an input block over which the macro is applied.

They have the following structure:

'.'<macro-name> ['(' <parameters> ')' ]
<macro-block-input>
'.'end<macro-name > [ '(' <tail> ')' ]

<tail> is an optional string constant appended to the generated text, if there is one.

Loop-macro

Loop macros are used for iteration. At each iteration, a new scope is created. The template specified inside the block is translated successively with respect to the iteration scope.

'.'foreach_<macro-name> ['(' <parameters> [',' <head> [',' <tail>]] ')' ]
<complex-template>
'.'next [ '(' <separator> ')' ]

<head> and <tail> are both optional string constants. <head> is generated before, and <tail> is appended to the generated text, if there is one.

A <separator> may optionally be specified as an argument to the .next keyword, it is placed between non-empty evaluations of <complex-template>.

Simple-macro

Simple macros are macros that hold on a single line.

Note   Macro parameters delimiters
Macro parameters may be delimited by double quotes. The delimiters are required whenever the parameter value includes commas, braces, leading or trailing blanks. The escape sequence for double quotes inside a parameter value is \" .

 


Copyright (C) 2005. Sybase Inc. All rights reserved.