Thread tagged as: Discussion, Docs

Perch replace tag attribute


I'm looking for more specific information on the limitations of the "replace" tag-attribute, as documented here:

It's also stated in this forum post

that "The values are taken as literal".

One thing I'm trying to do with it that isn't working is strip the domain from URLs pasted into a text field so that they can be root-relative in the system, if they include the domain of my site.

<perch:content id="headline_link_url" label="Headline link URL"
    help="<perch:template path="content/includes/" />"

(I'm using the suppress="true" just to separate my edit form from my output template, so that I can do the fields in different order).

Oh wait, that's it -- I had to put the replace code not in the first field definition, but in the non-suppressed one that I'm outputting later:

                <perch:if exists="headline_link_url">
                    <a href='<perch:content id="headline_link_url" replace="|/,|/" />'>

It appears that the replaced value isn't actually stored -- it's done at render-time (the result of which is stored under default usage, I know). OK, well, that's good to know.

Oh well, I was hoping that I could be storing the root-relative URLs only, but at least I can transform them for output.

I'm posting here in case someone else might stumble across it.


Aaron Wallentine

Aaron Wallentine 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

That's right replace is for output, as in some cases people might use it in order to store a value and then display it differently only in some circumstances.

If you need to do some processing on input you could look at creating a simple Field Type.