Extension Magento Advanced Content Manager 2
Pour Magento 1
Pour Magento 2

Create and Manage Repeater Fields


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.

Display the repeater

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

<?php echo $content->render('my_repeater_identifier');?>

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

You can also retrieve a collection of repeater fields like this

  $repeaterValues = $content->getContentCollection('my_repeater_identifier', '*');

and then print out some data :

  echo $repeaterValues->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 byGlobalContent Type
Repeater fields / view/<repeater_field_identifier>/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 :

  $content = $block->getContent();
  echo $content->render('my_image_identifier');

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 :

<?php echo $content->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.