Create and Manage Repeater Fields

Overview

Repeater fields are a set of subfields (text, images, etc...) that can be easily repeated as much as needed when editing your content.

Create and Manage Repeater fields

1- Create your Repeater field

Before using the repeater fields in your contents you will have to define a structure based on at least field type. A structure is like a model that you will be able to repeat in your content as you wish.

To create a repeater field structure:

> Open the “CONTENT” menu in the admin

> Click ‘Repeater Fields’

On this page you can view/edit/delete your already existing Repeater Field structures or add new ones:

> Click ‘Add new repeater Field’ to add a new Repeater Field structure

Repeater Fields Information

In this first tab you have to put the basic information that will be used to identify your repeater field structure.

> Title: Name of your repeater field. For admin purpose.

> Identifier: Unique ID to identify your repeater field.

> Default status: status of the repeater field structure : enable or disable.

> Description: for admin purposes, appears in the grid?

Manage Fields

This is the part where you will be able to add some custom field in your repeater field. For example if you add an image and a text area you will be able to repeat this exact structure (a field image and a field text area) in your contents as much as you want.

The principle is the same as when you manage the field of a content type.

In this example we added two input types : “my_image” of type “image” and “my_area” of type “area”. Later, we will be able to repeat these fields over and over in differents content types.

You can click save and you own now a Repeater Field structure.

2- Add the repeater to a Content Type

Now that we have our Repeater Field structure ready, we have to add it into a Content Type. A Repeater Field structure works like other custom fields. Once you have your Content Type you can manage its fields and you can also add a repeater field structure.

To add a repeater field you have to Click “Add New Field” and select for “Input Type” => “Repeater Fields”. Then select for “Repeater Fields Type” the Repeater Field structure you have created previously.

You can click on “Save” and you have now a Content Type that can use this repeater fields.

3- Create your Content

After creating your content type and adding a repeater field into it, you can create a content and finally use this repeater field.

If you are new to ACM2 you should check how to add a content first.

Now that you have your content you can see that you you have a button “Add field” that will allow you to repeat the structure that you have previously made (ie : an image and a text area).

You can now fill it up with some content and start repeating this field as long as you need to.

Click on “Save” and you have now a Content with repeater fields inside.

Additional capabilities

  • Reordering: repeated entries can be reordered by drag and drop directly in the content edit form.
  • Nested repeaters: a repeater field structure can itself contain a field of type "Repeater Fields", allowing repeaters inside repeaters. This is technically supported but not recommended: each repeater level triggers its own database query to load its repeated entries (one query per parent entry, per level), so nesting repeaters can quickly multiply the number of queries needed to render a single content and noticeably degrade frontend display performance. Prefer flattening your structure when possible, and keep nesting to a minimum otherwise.
  • Use default value: on a multi-store setup, each repeated entry can be overridden per store view. Unchecking "Use default value" for a store view lets you define a store-specific set of repeated entries; checking it back reverts to the entries defined on the default (All Store Views) scope.
  • Import / Export: repeater field values can be imported and exported along with your contents (see Import/Export your content). The column header combines the repeater field identifier with its sub-fields' identifiers, and multiple repeated entries are serialized in a single cell using the separators configurable in System Configuration. This does not support nested repeaters: a repeater field nested inside another repeater is not expanded into its own sub-fields in the export/import column, so its data cannot be reliably exported or re-imported this way.

Display the repeater

In the template custom template of your content you can simply call the render method like this :

echo <span class="variable">$content</span>->render(<span class="string">'my_repeater_identifier'</span>);?>

Now this will simply print each repeaters with each other after each other.

You can also retrieve a collection of repeater fields like this


  `<span class="variable">$repeaterValues</span> = <span class="variable">$content</span>->getContentCollection(<span class="string">'my_repeater_identifier'</span>, <span class="string">'*'</span>);` `?>` 

and then print out some data :

<span class="function">echo</span> <span class="variable">$repeaterValues</span>->getFirstItem()->getData(‘my_textarea_identifier’) ?>

If you would like to change how the repeater itself is rendered you should override the template of the repeater itself. You will see how to do this in the next section.

Overriding templates

    View / Override by Global Content Type     Repeater fields / view//view.phtml    

In this template you can call the methods like you would do if you were overriding a content template.

For example you can render an image field like this :


  `<span class="variable">$content</span> = <span class="variable">$block</span>->getContent();` `<span class="function">echo</span> <span class="variable">$content</span>->render(<span class="string">'my_image_identifier'</span>);` `?>` 

Where ‘my_image_identifier’ should be the identifier of your image field (for example) that is in your repeater field model.

You can also print a text like you would do in a content template :

echo <span class="variable">$content</span>->getData(‘my_textarea_identifier’);?>

Where ‘my_textarea_identifier’ should be the identifier of your text area field (for example) that is in your repeater field model.

Loading...