CodeGen Documentation
CodeGen Documentation

Key Segment Loops

 

A key segment loop is a template file construct which allows you to iterate through the collection of key segments for a particular key that CodeGen has information about.  In order to use a key segment loop you must be processing a repository structure, either directly via the –s command line option, or because the structure is referenced by the UI Toolkit input window that you are processing via the –w command line option, and must be inside a key loop.

Key segment loops are delimited by a matching pair of <SEGMENT_LOOP> and </SEGMENT_LOOP> tags, which surround the template code to be inserted for each key segment.

Key segment loop tokens are tokens that can only be used within a key segment loop:

Key Segment Loop Expansion Tokens

Key Segment Loop Expression Tokens

There are two types of key segment loop, multi-line key segment loops and in-line key segment loops.

Multi-Line Key Segment Loops

Multi-line key segment loops occur when the opening and closing key segment loop tags appear on separate lines in a template file, and delimit one or more entire lines of template code, like this:

<KEY_LOOP>
[code]
<SEGMENT_LOOP>
code
</SEGMENT_LOOP>
[code]
</KEY_LOOP>

Multi-line key segment loops generate one or more lines of output code for each key segment that is processed.

In-Line Key Segment Loops

In-line key segment loops exist when the opening and closing key segment loop tags appear on the same line in a template file, and delimit part of a line of template code, like this:

<KEY_LOOP>
[code]
[code] <SEGMENT_LOOP> code </SEGMENT_LOOP> [code]
[code]
</KEY_LOOP>

In-line key loops generate code into the current output line only.

Note: Key segment loops can also be used within alternate key loops and primary key blocks. Also, in the last example, the outer key loop could also be an in-line key loop.

The code between the opening and closing tags of a key segment loop is repeated for each key segment in the key being processed.

This code within a key segment loop can contain generic tokens, structure tokens, and special key segment loop tokens, which are discussed later. Most key loop tokens can also be used inside a key segment loop.

Key segment loop tokens can only be used inside a key segment loop, and a key segment loop can only be declared within one of the supported key loop constructs.

Key Segment Filter Loops

A key segment filter loop is similar to a key segment loop; except that the final key segment is not processed.  As with key segment loops, CodeGen supports both multi-line and in-line key segment filter loops.

A multi-line key segment filter loop looks like this:

<KEY_LOOP>
[code]
<SEGMENT_LOOP_FILTER>
code
</SEGMENT_LOOP_FILTER>
[code]
</KEY_LOOP>

And an in-line key segment filter loop looks like this:

<KEY_LOOP>
[code]
[code] <SEGMENT_LOOP_FILTER> code </SEGMENT_LOOP_FILTER> [code]
[code]
</KEY_LOOP>

Note: Key segment filter loops can also be used within alternate key loops and primary key blocks. Also, in the last example, the outer key loop could also be an in-line key loop.

If you use a segment filter loop with a key which only has one segment, then no code will be inserted into the output file.

First Segment Restrictions

A first segment restriction behaves in a similar way to a key segment loop; except that only the first key segment is processed.  As with key segment loops, CodeGen supports both multi-line and in-line first segment restrictions.

A multi-line first segment restriction looks like this:

<KEY_LOOP>
[code]
<FIRST_SEGMENT>
code
</FIRST_SEGMENT>
[code]
</KEY_LOOP>

And an in-line first segment restriction looks like this:

<KEY_LOOP>
[code]
[code] <FIRST_SEGMENT> code </FIRST_SEGMENT> [code]
[code]
</KEY_LOOP>

Note: first segment restrictions can also be used within alternate key loops and primary key blocks. Also, in the last example, the outer key loop could also be an in-line key loop.

Second Segment Restrictions

Similar to a first segment restriction, as second segment restriction can be used to indicate that only the second segment of a key should be processed within a key loop. This can be particularly useful when processing structures that have a structure tag value as the first key segment and the main useful segment of the key is often then the second segment.

A multi-line second segment restriction looks like this:

<KEY_LOOP>
[code]
<SECOND_SEGMENT>
code
</SECOND_SEGMENT>
[code]
</KEY_LOOP>

And an in-line first segment restriction looks like this:

<KEY_LOOP>
[code]
[code] <SECOND_SEGMENT> code </SECOND_SEGMENT> [code]
[code]
</KEY_LOOP>

 

 

 


Copyright © 2021  Synergex International, Inc.