We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

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

  • 1 month 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): http://forum.grabaperch.com/forum/01-20-2018-remove-spaces-from-field

Drew McLellan

Drew McLellan 2637 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): http://forum.grabaperch.com/forum/01-20-2018-remove-spaces-from-field