# Issue with repeater field

**URL:** <https://community.hubspot.com/t/issue-with-repeater-field/3406>\
**Category:** CMS Development\
**Created:** [September 22, 2017, 1:56pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406 "2017-09-22T13:56:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [September 22, 2017, 1:56pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/1 "2017-09-22T13:56:23Z")

</div>

Hi guys!  
I’m working on a landing page and i just made a repeater field with this code i found on the hubspot docs page.

```auto
{% set my_options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %}
{% choice "repeats" label="Number of modules to print", value="1", choices="{{ my_options }}", export_to_template_context=True %}
{% for options in my_options %}
 {% if loop.index <= widget_data.repeats.value %}
 {% linked_image "repeated_image" label="Repeated image", alt="Photo of Brian Halligan", src="//cdn2.hubspot.net/hub/53/file-733888619-jpg/assets/hubspot.com/about/management/brian-home.jpg", unique_in_loop=True %}
 {% text "repeated_caption" label="Repeated caption", value="Insert caption here", unique_in_loop=True %}
 {% endif %}
{% endfor %}

```

I have an issue with the labels i each iteration of the foor loop, it creates the fields correctly, but the labels are the same for every iteration, i tried to put the index of the loop inside the label of the custom module like this:

`{% text "repeated_caption" label="Repeated caption-{{loop.index}}", value="Insert caption here", unique_in_loop=True %}`

But when i go to edit the page it doesn’t work, is there anyway i can identify every label differently?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [September 25, 2017, 8:05am UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/2 "2017-09-25T08:05:42Z")

</div>

@mateomm22

I have a nifty trick for this. You will need to use block syntax for the modules inside of the loop (find it here in the [docs](http://designers.hubspot.com/docs/hubl/hubl-module-syntax-and-parameters)).

```auto
{% widget_block rich_text "my_rich_text_module" overrideable=True, unique_in_loop=True %}
 {% widget_attribute "label" %}
 My rich-text module {{ loop.index }}
 {% end_widget_block %}
 {% widget_attribute "html" %}
 <h2>New Module</h2>
 <p>Add content here.</p>
 {% end_widget_attribute %}
{% end_widget_block %}

```

Notice 2 things:

1. unique\_in\_loop=true - makes the system name for the module unique

2. widget\_attribute label - I broke the label loose using block syntax and set the loop index at the end to make it unique.  
You should know that the ordering of modules using this method is utter chaos on the editor page. Instead of it display:

text 1

image 1

text 2

image 2

text 3

image 3

it will be more like:

image 3

text 1

text 2

image 1

text 3

image 2

It’s a bit of a mess. Makes for some pretty decent customization though.

---

<div class="post-metadata">

**Author:** ![nicolebrenner](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/nicolebrenner/32/64853_2.png) [@nicolebrenner](https://community.hubspot.com/u/nicolebrenner)\
**Post date:** [September 25, 2017, 4:41pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/3 "2017-09-25T16:41:15Z")

</div>

Thanks for sharing @jsum! @mateomm22, please let us know if this solution helped you!

---

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [September 25, 2017, 4:59pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/4 "2017-09-25T16:59:54Z")

</div>

Awesome!  
I’ll try it and i’ll tell you if that worked for me

---

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [October 2, 2017, 3:01pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/5 "2017-10-02T15:01:34Z")

</div>

Hi there!  
Unfortunately this didin’t work, and somehow the last field I’m creating isn’t at the same order than the others

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [October 2, 2017, 6:30pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/6 "2017-10-02T18:30:48Z")

</div>

@mateomm22,

Can you show your code to help me understand what youa re talking about?

I’ve used this tons of tiems so it should work no problem.

---

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [October 2, 2017, 6:34pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/7 "2017-10-02T18:34:13Z")

</div>

```auto
{% set my_options = [1, 2, 3, 4, 5, 6] %}
{% choice "repeater" label="Número de destinos", value="2", choices="{{ my_options }}", export_to_template_context=True %}

{% for options in my_options %}
 {% if loop.index <= widget_data.repeater.value %}
 {% text "destino" label="Destino", value="Colombia", unique_in_loop=True, export_to_template_context=True %}
 {% widget_block text "precio" value="6 días - USD 1.250", unique_in_loop=True, export_to_template_context=True %}
 {% widget_attribute "label" %}
 Incluye {{ loop.index }}
 {% end_widget_attribute %}
 {% end_widget_block %}
 {% rich_text "fecha_salida" label="Fecha de salida", html='<p>Fecha de salida</p><p><strong>8 diciembre de 2017 a 4 de enero de 2018</strong></p>', unique_in_loop=True, export_to_template_context=True %}
 {% endif %}
{% endfor %}

```

I’m creating this loop, but it doesn’t print the label as you showed me

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [October 2, 2017, 7:06pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/8 "2017-10-02T19:06:50Z")

</div>

You were only applying the loop.index to the middle module in the loop. I refractored:

```auto
{% set my_options = [1, 2, 3, 4, 5, 6] %}
{% choice "repeater" label="Número de destinos", value="2", choices="{{ my_options }}", export_to_template_context=True %}

{% for options in my_options %}
 {% if loop.index <= widget_data.repeater.value %}
 {% widget_block text "destino" value="6 días - USD 1.250", unique_in_loop=True, export_to_template_context=True %}
 {% widget_attribute "label" %}
 Destino {{ loop.index }}
 {% end_widget_attribute %}
 {% end_widget_block %}
 {% widget_block text "precio" value="6 días - USD 1.250", unique_in_loop=True, export_to_template_context=True %}
 {% widget_attribute "label" %}
 Incluye {{ loop.index }}
 {% end_widget_attribute %}
 {% end_widget_block %}
 {% widget_block rich_text "fecha_salida" unique_in_loop=True, export_to_template_context=True %}
 {% widget_attribute "label" %}
 Fecha de salida {{ loop.index }}
 {% end_widget_attribute %}
 {% widget_attribute "html" %}
 <p>Fecha de salida</p><p><strong>8 diciembre de 2017 a 4 de enero de 2018</strong></p>
 {% end_widget_attribute %}
 {% end_widget_block %}
 {% endif %}
{% endfor %}

```

I tested and all of the modules have a number in the page editor

---

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [October 2, 2017, 7:19pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/9 "2017-10-02T19:19:43Z")

</div>

I don’t know what’s wrong with my code, but here is what the page editor is showing me.  
I pasted the same code you gave me.

 ![Screen Shot 2017-10-02 at 2.17.08 PM.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/4/6457f7c00ea18e7f55514359886965b451a43a9a.jpeg)

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [October 2, 2017, 7:26pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/10 "2017-10-02T19:26:44Z")

</div>

is it possible that you are updating the wrong template?

try creating a new landing page from the right template. I’ve confirmed the code works on my end, unless there is a caching issue or you are using the wrong template, I’m not sure why it isn’t working.

---

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [January 26, 2018, 3:06pm UTC](https://community.hubspot.com/t/issue-with-repeater-field/3406/11 "2018-01-26T15:06:57Z")

</div>

Hi @Jsum!  
The solution you gave me has worked perfectly, but I have another question.

```auto
{% widget_block custom_widget "some_content" widget_name='Custom module Name', unique_in_loop=True, export_to_template_context=True %}
 {% widget_attribute "label" %}
 Custom label {{ loop.index }}
 {% end_widget_attribute %}
{% end_widget_block %}

```

For some reason the same code doesn’t work with custom modules inserted into the template, is there a way I can edit the label of the **custom\_widget** module?  
Thanks a lot!
