Processing arrays of items by creating repeating regions
Create repeating regions for the same types of items occurring repeatedly in your Page or Component, such as a list of news articles on a Page. Styles and formatting applied in such a region applies to all items in the region. Typical uses of a repeating region are to process the Components on a Page, or to process the fields in a Component.
Procedure
- Start Adobe Dreamweaver, and open an Adobe Dreamweaver Template.
- From the main menu, choose Insert > Template Object > Repeating Region.
- Enter a name for the repeating region. The name of the repeating region is an expression which refers to an array used in the package. For example, to process Components on a Page, give the repeating region the name of the array of Components in your package (typically
Components). When in doubt, the implementer supplying you with the package can tell you which name to enter here. Then click OK.Dreamweaver inserts the following:
<!-- TemplateBeginRepeat name="ARRAY_ITEM_NAME" --> <!-- TemplateEndRepeat -->where ARRAY_ITEM_NAME is the name of the array you entered.
- Inside these tags, write code to produce output. Simply writing a variable will output its value. You have various predefined variables at your disposal inside the tags:
- Iterator variable
-
Each array has a variable associated with it that corresponds to the current item in this iteration. This variable is always called
TemplateRepeatIndex. Note that this means that you cannot access the index of the outermost loop when you are inside a nested repeating region. In such an event, useFieldPathinstead.TemplateRepeatIndexis 0-based, but note that when using this index inside a CSS tag, you must add 1 to it. - Current item variables
-
Each type of array has a variable associated with it that corresponds to the current item in this iteration:
- If the array contains Components, use the variable name
Componentfor the current item. - If the array contains Component Presentations, use
Componentfor the current Component andComponentTemplatefor the current Component Template. - If the array contains Fields, use
Field. - If the array contains values of a multivalue field, use
Fieldas well. - In a loop, use
FieldPathto retrieve the full path to the item being iterated over.
- If the array contains Components, use the variable name
- Array-in-array variables
-
Each type of array has variables associated with it that correspond to further arrays contained within this array, which you can use as repeating region names:
- Inside an array of Components, use
Fieldsas a region name to refer to the array of Component fields for the current Component. - Inside an array of Fields, when processing a multivalue field, use the name of that multivalue field as a region name to refer to the array of values of the multivalue field. For example, if a Component has a multivalue field called 'Countries', first write a conditional to check if you are processing 'Countries' and if so, write a new repeating region named 'Countries'.
- Inside an array of Components, use
For example, the following fragment writes the index number and name of each Component in the
Componentsarray:<!-- TemplateBeginRepeat name="Components" --> @@TemplateRepeatIndex@@: @@Component.Name@@ <!-- TemplateEndRepeat -->