How do I concatenate strings with HUBL?

Highlighted
Occasional Contributor

How can I concatenate strings with Hubl? The docs suggest there is a special operator for it (~), however I have tried to use it in many different ways and I can't preduce the behaviour I expect.

 

I need to loop through an list and build up a string with the contents of the list. I have tried this and after the loop the 'items' variable has no value...

 

{% set items = "" %}

{% for row in hubdb_table_rows(1034058, "orderBy=random()") %}
{{ items = items ~ ("Test"+loop.index0+", ") }}
{% endfor %}
<div>{{ items }}</div>

 

Has anyone managed to do this before?

Reply
0 Upvotes
3 Replies
Esteemed Contributor | Platinum Partner

 

{% set items = [] %}
{% for x in array %}
       {% set _dummyvar = items.append(x) %}
{%endfor %}

{{items}}


This wont get you 100% of the way but will get you most of the way. Wasn't entirely sure I understood what you were intending to do.

Advisor

@BillOddie you'll want to use the tilde in the statement rather than the expression. For example:

{% set items = "string 1" ~ "string 2" %}

Hope that helps!

Occasional Contributor

Hello, 

 

Thank you both for your answers.

 

I ended up using join| filter to print the list as a string with a custom delimiter. 

 

Sorry if my question was confusing

 

Reply
0 Upvotes