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…
Hi @BillOddie ,
Please try the below code:
{% set str_C = ‘’ %}
<ul>
<li data-position=“{{ row.price }}” data-ID=“{{ c }}” class=“content domain-block project f-{{ row.sort_by[0].id }} {% for new_row in row.sort_by %}{% if(str_C != ‘’) %}{% set str_C = str_C ~ ’ ’ ~ new_row.name|replace(’ ‘,’-‘) %}{% else %}{% set str_C = ’ ’ ~ new_row.name|replace(’ ‘,’-‘) %}{% endif %}{{str_C|replace(’_‘,’ ')}}{% endfor %}” data-filter=“f-{{ row.sort_by[0].id }}”>
</li>
</ul>ORPlease try this but not passed values out the for loop:
{% set test_varC = ‘’ %}
{% macro render_dialog(items,test_varC) %} {% for x in items %}
{% set test_varC = test_varC ~ x %}
<h1>
{{test_varC}}
</h1>
{% endfor %}{% endmacro %}
{% set items = [‘item 1’, ‘itme 2’, ‘item 3’] %}// Function call
{% call render_dialog(items,test_varC) %}
{% endcall %}
Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.