Split and delete Text

Hello everyone,
I have this code:

{% 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:

{%- set Player_Name = ['Keuken Sonos', 'Slaapruimte MB Sonos'] %}
{{ Player_Name|map('replace','Sonos', '') | map('slugify') | join('\n') }}

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.

Thanks for your reply.

Is it that simple? :grimacing:

I’ve been searching for an hour! :innocent:

What does ‘slugify’ actually do?

Building Templates - String Filters - #2

slugify turns a string into a “slug”, which is a trimmed string containing only lower case letters, numbers, and underscores.