Limit the Number of For Loops

SOLVE
EJackson23
Participant

I'd like to limit the number of loops so it doesn't show more than 10 records. I've tried adding the range function but I'm not exactly sure where to put it. Thanks for you help.

 

{% set contact_id = contact.hs_object_id %}

{% set associated_objects = crm_associations(contact_id, 'USER_DEFINED', 30, 'orderBy=account_row_id', 'account_row_id,acct_uom,acct_commodity,lastmonth_date,lastmonth,thismonth_date,thismonth,month1,month1_date,month2,month2_date,month3,month3_date,month4,month4_date,month5,month5_date,month6,month6_date,month7,month7_date,month8,month8_date,month9,month9_date,month10,month10_date,month11,month11_date') %}

{% for energyresi in associated_objects.results %}

 

All my html

{% endfor %}

1 Accepted solution

Accepted Solutions
himanshurauthan
Solution
Recognized Expert | Platinum Partner

Hello @EJackson23,

 

I would recommend limiting the results by 10 objects only, and you can do that like this example -

 

{% set associated_objects = crm_associations(contact_id, 'USER_DEFINED', 30, 'limit=10&orderBy=account_row_id', 'account_row_id,acct_uom,acct_commodity,lastmonth_date,lastmonth,thismonth_date,thismonth,month1,month1_date,month2,month2_date,month3,month3_date,month4,month4_date,month5,month5_date,month6,month6_date,month7,month7_date,month8,month8_date,month9,month9_date,month10,month10_date,month11,month11_date', false) %}

 

I hope this helps,

 

Have an amazing day ahead!

Digital Marketing & Inbound Expert In Growth Hacking Technology

View solution in original post

3 Replies 3
himanshurauthan
Solution
Recognized Expert | Platinum Partner

Hello @EJackson23,

 

I would recommend limiting the results by 10 objects only, and you can do that like this example -

 

{% set associated_objects = crm_associations(contact_id, 'USER_DEFINED', 30, 'limit=10&orderBy=account_row_id', 'account_row_id,acct_uom,acct_commodity,lastmonth_date,lastmonth,thismonth_date,thismonth,month1,month1_date,month2,month2_date,month3,month3_date,month4,month4_date,month5,month5_date,month6,month6_date,month7,month7_date,month8,month8_date,month9,month9_date,month10,month10_date,month11,month11_date', false) %}

 

I hope this helps,

 

Have an amazing day ahead!

Digital Marketing & Inbound Expert In Growth Hacking Technology

View solution in original post

EJackson23
Participant

Thank you Himanshu. This worked great.

0 Upvotes
webdew
Top Contributor | Diamond Partner

Hi @EJackson23 ,

This function returns an object with the following attributes: has_more, total, offset and results.
You can pass offset number in association hubl function:
Screen shot : https://prnt.sc/1gzol30


Please have look this documentation :
https://developers.hubspot.com/docs/cms/hubl/functions

Example :
{% set associated_objects = crm_associations(<contact_vid>, 'USER_DEFINED', 30, 'offset=<offset_interger>', false) %}

Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards. 

0 Upvotes