{% set Player_Name = 'Keuken Sonos', 'Slaapruimte MB Sonos' %}
{% for Name in Player_Name %}
{% set Who = Name|replace('Sonos',"")|replace("","") %}
{{Who|join('_')}}
{% endfor %}
This results in:
K_e_u_k_e_n_
S_l_a_a_p_r_u_i_m_t_e_ M_B
But I would like to have the following result:
keuken
slaapruimte_mb
I’ve tried everything, but I can’t figure it out.
Seems simple to me, but still?
{%- set Player_Name = ['Keuken Sonos', 'Slaapruimte MB Sonos'] %}
{%- for Name in Player_Name %}
{%- set Who = Name|replace('Sonos', '') %}
{{Who|slugify}}
{%- endfor %}
You can also do it without the loop by using the map filter:
This method would also allow you to return a functional list by using list instead of join. To do the same with the loop you would need to include a namespace.