Forum

Thread tagged as: Question

Replace Tag

I am trying to replace spaces with hyphens using the replace tag. For example. the content might be "Joe Smith" and I want to output "Joe-Smith". Here's my code

<perch:content id="staff_last_name" type="text" label="Staff Last Name" replace=" |-"> 

but the tag as constructed here is ignored. I've verified that Replace is otherwise working by replacing other alpha characters in the string.

Any thoughts on how to coax Replace into working with a space between characters?

JP McLaughlin

JP McLaughlin 0 points

  • 2 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello JP,

I think you need to use a Template Filter: https://docs.grabaperch.com/api/template-filters/

Here's a post discussing something very similar (solution included): https://forum.grabaperch.com/forum/01-20-2018-remove-spaces-from-field

Drew McLellan

Drew McLellan 2638 points
Perch Support

Otherwise the next closest thing would be the urlify attribute, but that will also convert to lowercase.

Thank you Hussein! That was the ticket.

Hussein Al Hammad said:

Hello JP,

I think you need to use a Template Filter: https://docs.grabaperch.com/api/template-filters/

Here's a post discussing something very similar (solution included): https://forum.grabaperch.com/forum/01-20-2018-remove-spaces-from-field