How do I strip spaces from a Twig variable? Example code I'm working with:

&lt;a{{ attributes.addClass(classes, 'field__item') }} name="{{ item.content }}"&gt;{{ item.content }}&lt;/a&gt;


In this example, I have created a Brick with a field called anchor_id. The idea is that content creators can name an anchor whatever they want, and then add that brick to a page.

I can get the field to show up fine. But, I'd like to strip out spaces so if they enter "my awesome tag" it instead gets rendered as name="myawesometag.

I've tried a few methods, but can't seem to figure it out. Seems like it would be some simple filter, but if it is I'm not seeing it.

Thanks in advance!
You can use "replace" - much like you would in PHP - and replace the space with no space

{{ anchor_id|replace({' ': ''})


More info: https://twig.symfony.com/doc/3.x/filters/replace.html