Forum
Replace/insert variable within template tag output
May be asking a bit much here but client would like to be able to edit a line of text in the CMS that actually needs to contain a computed value, e.g. "Your booking number is [[computed]]. You will receive an email."
I know I can pass the booking number into the template using PerchSystem::set_var
but trying to figure out how to place this within a CMS-editable line of text.
Two options that sprang to mind:
1) Create a field for the content before and after the computer value, but this feels a little clunky:
<perch:content id="textPrefix" type="text" label="Text prefix" />
<perch:content id="bookingID" type="hidden" label="Text prefix" />
<perch:content id="textSuffix" type="text" label="Text suffix" />
2) Create a form of custom markdown, then replace it. I imagine I would need to use perch_content_custom
and a PHP find/replace, unless there was a way to use the Perch 'replace' tag attribute?
"Your booking number is [[BOOKINGID]]. You will receive an email."
3) Something I haven't thought of?
Thanks :)
Read a little about custom field types - not sure if it could pick up a system variable from within a template?
Ooh, actually I recall being able to take content out of a template, process it, then send it back to the template for render - just need to find the documentation or example of when I did it in the past!
Found it: https://forum.grabaperch.com/forum/05-20-2015-perch-2-creating-related-content-using-each
I'll post my solution.
Yep, that worked:
All sorted?