Show TOC

repeatLocate this document in the navigation structure

The <template:repeat instruction iterates the sap.ui.model.ListBinding given by the list attribute.


Sorting and filtering is already supported by the list binding via an extended syntax. For more information, see Using Extended Syntax to Add Filters and Sorters.

The var attribute holds the name of the loop variable which can be used to access the current list element in a child element of repeat. In the preprocessing, repeat is replaced by multiple clones of its content, one clone per list element, with each clone again preprocessed as if it were contained in a with instruction defining the loop variable.

The following example iterates all fields in the identification annotation from the SAP UI vocabulary in the currently referenced element of the model meta and displays a label and content for each field. It is completely transparent to the repeat implementation whether the list binding refers to data or meta data. The templating engine is replacing "template time" binding expressions which refer to meta data with corresponding runtime binding expression which refer to data. The formatter sap.ui.model.odata.AnnotationHelper.format is used, which encapsulates knowledge about the SAP UI vocabulary and so on.

Example: Template for "repeat" Instruction

<template:repeat list="{meta>}" var="field">
  <Label text="{path: 'field>Label', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
  <Text text="{path: 'field>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />

Example: Output Template for the "repeat" Instruction (in Memory Only)

<Label text="Product ID" />
<Text text="{path:'ProductID',type:'sap.ui.model.odata.type.String',constraints:{"nullable":false,"maxLength":10}}" />
<Label text="Price" />
<Text text="{path:'Price/Amount',type:'sap.ui.model.odata.type.Decimal',constraints:{"precision":13,"scale":3}}" />
<Label text="Category" />
<Text text="{path:'Category',type:'sap.ui.model.odata.type.String',constraints:{"maxLength":40}}" />
<Label text="Supplier" />
<Text text="{path:'SupplierName',type:'sap.ui.model.odata.type.String',constraints:{"maxLength":80}}" />

Example: Template for the "repeat" Instruction with startIndex and length

You can start the iteration at an index other than 0 or limit the length of the iterated list in the usual manner. For this, specify startIndex and length. Both are optional and the defaults are 0 for startIndex and full length for length.

<template:repeat list="{path:'entityType>',startIndex:1,length:3}" var="field">
  <!-- ... -->

As the OData meta model supports filtering by name, you can repeat all FieldGroup annotations regardless of their qualifier.


In JSON content, the annotation can be called or, and so on, depending on its qualifier. The filter that is used in the following code snippet for the <template:repeat> instruction uses the special path name which refers back to the name of the object that is inspected for filtering. This name is, for example,

Example: Filter By Annotation Term

<template:repeat list="{path:'entityType>', filters: {path: '', operator: 'StartsWith', value1: ''}}" var="fieldGroup">
      <core:Title text="{path: 'fieldGroup>Label', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}"/>
    <template:repeat list="{fieldGroup>Data}" var="field">
      <Label text="{path: 'field>Label', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}"/>
      <core:Fragment fragmentName="sap.ui.core.sample.ViewTemplate.scenario.Field" type="XML"/>