Forum

Thread tagged as: Discussion, Docs

Perch replace tag attribute

Hi,

I'm looking for more specific information on the limitations of the "replace" tag-attribute, as documented here: https://docs.grabaperch.com/docs/templates/attributes/replace/

It's also stated in this forum post https://forum.grabaperch.com/forum/05-11-2016-using-the-replace-tag-to-convert-newline-to-br

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"
    type="text"
    suppress="true"
    replace="https://mydomain.com/|/,https://www.mydomain.com/|/"
    help="<perch:template path="content/includes/link_url_helptext.pt.html" />"
/>

(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="https://mydomain.com/|/,https://www.mydomain.com/|/" />'>
                </perch:if>

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.

Thanks!

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.

https://docs.grabaperch.com/addons/field-types/