-
Notifications
You must be signed in to change notification settings - Fork 2
Syntax Implicit Iterator Pragma
The interpreter reserves one tag name
for Interpolation tags to enable simple Array iteration Sections (note the simple Array iteration is described in the Section tag article). By default this tag name is .
. The IMPLICIT-ITERATOR
pragma can be used to alter this reserved tag name if necessary.
The pragma takes one option: iterator
. The value of iterator
will be used as the Implicit Iterator tag key for the scope of the template file.
Assuming the following data set:
{ fields: [ 'Wile E. Coyote', 'Yosemite Sam', 'Elmer Fudd' ] }
The following Mustache template:
{{%IMPLICIT-ITERATOR iterator=bugs}}
{{#fields}}{{bugs}}:{{/fields}}
Will output the following result:
Wile E. Coyote:Yosemite Sam:Elmer Fudd:
Note that the placement of the pragma does not matter. That is:
{{#fields}}{{%IMPLICIT-ITERATOR iterator=bugs}}{{bugs}}:{{/fields}}
Will output the same result.
Also note that pragmas are only parsed once, from the top of the file to the bottom of the file. If multiple IMPLICIT-ITERATOR pragas are present, the last one takes precendence. Therefore, the following template:
{{%IMPLICIT-ITERATOR iterator=bugs}}
{{#fields}}{{bugs}}:{{/fields}}
{{%IMPLICIT-ITERATOR iterator=daffy}}
Will output an unexpected result (:::
)