Forum
Accessing variables in templates without perch_content_custom
Is is possible to get things like the current page url from within a template, without resorting to perch_content_custom?
I often have the need to get the page url, site domain or details like an email address, in different places in multiple templates. An example would be linking sharing buttons or mail-to buttons. I know how to pass variables into templates using perch_content_custom, but I prefer to stick with perch_content if possible.
I wish there was a more simple way to handle these kind of things in Perch templates without going all php. It would be great: a) to be able to set up a region in 'globally-shared' mode and then have all those id's automatically available in any template without further hassle b) having a perch template tag that outputs page url.
You could certainly do that with the API.
Hi Tim,
It does involve going a bit PHP, but it is quite straightforward to set variables on the page to be used in the templates:
But this might not be what you are after
Hi Mike,
Yeah that's the way I'm doing it now but I was looking for a way that could work with perch_content() as apposed to perch_content_custom().
Maybe it's not a big deal. I got hung up on the docs saying "It is important to note that perch_content_custom() should not be used to replace all of your perch_content tags." https://docs.grabaperch.com/functions/content/perch-content-custom/
Most of the time I have to choose between doing everything with perch_content_custom() or slice up the template in a way that makes no sense in the admin.
perch_content_custom()
is still nice and fast. It's just not as super-fast asperch_content()
.