I’m a noob with HUBL so I’m probably missing something obvious. I’m trying to split out a contact property into an array. I can get it to work when passing a string to the split(..) filter, but it fails when I put that string in the contact property.
My code is:
{% set string_to_split = contact.industry %}
string to split:
{{string_to_split}}<br />
{% set names = string_to_split|split(‘;’, 9) %}
Names: {{names}}<br />
<ul>{% for name in names %}
<li>{{ name }}</li>{% endfor %}
</ul>
{% set string_to_split = “Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda” %}
string to split:
{{string_to_split}}<br />
{% set names = string_to_split|split(‘;’, 9) %}
Names: {{names}}<br />
<ul>{% for name in names %}
<li>{{ name }}</li>{% endfor %}
</ul>
The first section doesn’t work: the split function doesn’t create multiple rows on the array, and just puts the whole string into one variable:
string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda]
- Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
But when i set the variable with a constant value, everything works as expected:
string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen, David, Cait, Nancy, Mike, Joe, Niall, Tim, Amanda]
- Stephen
- David
- Cait
- Nancy
- Mike
- Joe
- Niall
- Tim
- Amanda
I just can’t see why the split function doesn’t work the first time as the variable I’m passing is (on the face of it) the same both times. So why does the split function work on one, but not the other?
I’d really appreciate any help you can give
Thanks
Mike
