Using Parameter Passing

You can pass in, out or in/out parameters to a template through local variables by taking advantage of nested translation scopes. You can access parameters with the %@<number>% variable.

Example

Class templates:

Template 1

<show> template
<<<
Class "%Code%" attributes :
// Public
%publicAttributes%

// Protected
%protectedAttributes%

// Private
%privateAttributes%
>>>

Template 2

<publicAttributes> template
<<<
.foreach_item(Attributes)
 .if (%Visibility% == +)
 %DataType %Code%
 .endif
.next(\n)
>>>

Template 3

<protectedAttributes> template
<<<
.foreach_item(Attributes)
 .if (%Visibility% == #)
 %DataType %Code%
 .endif
.next(\n)
>>>

Template 4

<privateAttributes> template
<<<
.foreach_item(Attributes)
 .if (%Visibility% == -)
 %DataType %Code%
 .endif
.next(\n)
>>>

To give you more readability and to enhance code reusability, these four templates can be written in just two templates by using parameters:

First Template

<show> template
<<<
Class "%Code%" attributes :
// Public
%attributes(+)%

// Protected
%attributes(#)%

// Private
%attributes(-)%
>>>

Second Template

<attributes> template
<<<
.foreach_item(Attributes)
 .if (%Visibility% == %@1%)
 %DataType %Code%
 .endif
.next(\n)
>>>

Description

The first parameter in this example %attributes(+, or #, or -)% can be accessed using the variable %@1%, the second parameter when it exists, is accessed using the %@2% variable, etc ...