APIs & Integrations

andre9000
Contributor

Hubl: How to do a normal loop (print something n times)

SOLVE

Hi,

I want to do loop for 12 times:

{% set cols = 12 %}
{% for i in cols %}
// do something with i
{% endfor %}

However, this doesn't work, since cols is not an object or array. I don't want it to be, I want a plain loop for 12 times. How can I achieve this within HubL?

Thanks in advance :slight_smile:

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Hubl: How to do a normal loop (print something n times)

SOLVE

Hi @andreks,

It doesn't look like HubL has a method for this. All examples I've found use objects or arrays. Here's the simplest code I've come up with:

{% set iterations = range(1, 13) %}
{% for i in iterations %}
{{ i }}
{% endfor %}

Isaac Takushi

Associate Certification Manager

View solution in original post

1 Reply 1
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Hubl: How to do a normal loop (print something n times)

SOLVE

Hi @andreks,

It doesn't look like HubL has a method for this. All examples I've found use objects or arrays. Here's the simplest code I've come up with:

{% set iterations = range(1, 13) %}
{% for i in iterations %}
{{ i }}
{% endfor %}

Isaac Takushi

Associate Certification Manager