How to remove brackets in variables tied to multiselect properties?

SOLVE
Bob2245
Contributor | Diamond Partner

So, I've created a module that pulls in CRM data based on an ID provided by the content marketer editing the module. This pulling happens like so:

 

{% set crmProductQuery = "cxs_candidate_id=" + module.product_crm_id %}
{% set crmProductFields = "huidige_functietitel,opleidingsniveau,provincie,werkervaring,gewenste_uren_per_week" %}
{% set product = crm_object('cv', crmProductQuery, crmProductFields, true) %}

 

 

Where the field "opleidingsniveau" is a multiselect property with 3 options: MBO, HBO, WO.

 

This field is placed in the HTML code like so:

 

<p style="mso-line-height-rule:exactly; line-height:175%; text-align:left" align="left">{{ product.opleidingsniveau }}</p>

 

 

The result is that it renders like so in my emails:

Bob2245_0-1630396459867.png

 

As you can see, these brackets get added around the options array. They're not part of the field value, I checked.

 

Is there any way to strip those brackets from the rendered html?

0 Upvotes
1 Accepted solution

Accepted Solutions
Teun
Solution
Guide | Diamond Partner

Hi @Bob2245 ,

 

Could you check the output of the following:

 

 

{{ product.opleidingsniveau|pprint }}

 

 

It should show if this is a string or an array.


If it is an array, you could use the following:

 

 

{{ product.opleidingsniveau|join(', ') }}

 

 

 

If it is a string (which would be odd), you could do the following:

 

 

{{ product.opleidingsniveau|replace('[', '')|replace(']', '') }}

 

 



Did my answer solve your issue? Help the community by marking it as the solution.

View solution in original post

4 Replies 4
piersg
Key Advisor

It's returning an array so you should loop over it to get each individual item

<p style="mso-line-height-rule:exactly; line-height:175%; text-align:left" align="left">{% for item in product.opleidingsniveau %}{{ item }}{% unless loop.last %}, {% endunless %}{% endfor %}</p>
0 Upvotes
Teun
Solution
Guide | Diamond Partner

Hi @Bob2245 ,

 

Could you check the output of the following:

 

 

{{ product.opleidingsniveau|pprint }}

 

 

It should show if this is a string or an array.


If it is an array, you could use the following:

 

 

{{ product.opleidingsniveau|join(', ') }}

 

 

 

If it is a string (which would be odd), you could do the following:

 

 

{{ product.opleidingsniveau|replace('[', '')|replace(']', '') }}

 

 



Did my answer solve your issue? Help the community by marking it as the solution.

View solution in original post

Bob2245
Contributor | Diamond Partner

@Teun thanks! Second one fixed it, but I had to take out one of the )'s. So this did it:

{{ product.opleidingsniveau|join(', ') }}

 

0 Upvotes
Teun
Guide | Diamond Partner

Awesome! Sorry for the typo.



Did my answer solve your issue? Help the community by marking it as the solution.
0 Upvotes