Loop-related functions


loop() is designed to make looping through records for a browse page easier.

You can either pass in an array of record to loop through or, more commonly, the name of the model (e.g. ‘items’ or ‘collections’), whose records have already been set on the page.

loop(string $recordsVar, array|null $records)

Return an iterator used for looping an array of records.

  • $recordsVar (string) –
  • $records (array|null) –



Usually, the $recordsVar parameter is a string name of the model whose records have already been set in the view by the controller.

This will be the name of the table, i.e., the pluralized, underscored name of the model. For example, a CamelCase model name like “CsvImport_Import” should be “csv_import_imports”.

The string will be converted to the table name. Thus, csv_import_imports and CsvImport_Import have exactly the same effect (provided the same convention was used in setting the records to loop in the view).