Skip to main content
Solved

Looping over custom property of data type 'list'


rsmith
Problem Solver I
Forum|alt.badge.img+2
  • Problem Solver I
  • 4 replies

Anyone know how to access or loop over the values of a custom profile property of type “List”? In an attempt to condense the massive number of custom properties needed, I was hoping to pass all of the info into a custom property of type List and then iterate over them like an array or use syntax like “property[2]” to only pull values needed. However, I can’t seem to figure out how to access the values, especially in SMS.

 

I’ve attempted to use a sort of basic array syntax, such as “person.Reminder_OnBoard_Info[0]” and I’ve also attempted to leverage the {% for %} block. Is this possible with profile properties or only with event variables?

Any help or ideas are definitely appreciated! Thanks!!

 

- Ryan

Best answer by Dov

Hi @rsmith,

Thanks for sharing this with us.

You can use the person-look up tag to pull all of the values from this custom property. We have examples included in our documentation: Guide to Template Tags and Variable Syntax under the custom properties section. You can use “list to string” to convert it from displaying in the array format with the brackets and quotes into string data. Here’s an example of what that tag would look like if the custom property were “Interests” with the values of [“Hockey”, “Baseball”] after using list_to_string: 

{{ person|lookup:'Interests'|list_to_string }}

the output would be: “Hockey and Baseball”.

You can “pick out” a certain line-item in the array of list values using numbers to denote the numbers in the array. 0 would be the first item in the array, 1 would be the second item etc. So using the same example, if we wanted to display just “Hockey” under the custom property of “Interests” we would use:

{{ person.Interests.0 }}

or to display just “Baseball”:

{{ person.Interests.1 }}

I hope that’s helpful.

View original
Did this topic or the replies in the thread help you find an answer to your question?

2 replies

Dov
Forum|alt.badge.img+61
  • Klaviyo Alum
  • 1493 replies
  • Answer
  • May 19, 2022

Hi @rsmith,

Thanks for sharing this with us.

You can use the person-look up tag to pull all of the values from this custom property. We have examples included in our documentation: Guide to Template Tags and Variable Syntax under the custom properties section. You can use “list to string” to convert it from displaying in the array format with the brackets and quotes into string data. Here’s an example of what that tag would look like if the custom property were “Interests” with the values of [“Hockey”, “Baseball”] after using list_to_string: 

{{ person|lookup:'Interests'|list_to_string }}

the output would be: “Hockey and Baseball”.

You can “pick out” a certain line-item in the array of list values using numbers to denote the numbers in the array. 0 would be the first item in the array, 1 would be the second item etc. So using the same example, if we wanted to display just “Hockey” under the custom property of “Interests” we would use:

{{ person.Interests.0 }}

or to display just “Baseball”:

{{ person.Interests.1 }}

I hope that’s helpful.


rsmith
Problem Solver I
Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 4 replies
  • May 25, 2022

@Dov

Sorry for the delayed response. That’s excellent, thank you for sending that info over!