Forum
Using content:id in pages attribute
Hi,
I made a post some time ago:
which is now closed, however I would like to make my intention more clear.
I have a Perch content template:
<template id="upper_template">
<style><perch:template path="upper_image_styles.css"/></style>
<picture>
<source srcset="<perch:content id="webp" type="text" label="WebP image"/>" type="image/webp">
<img src="<perch:content id="jpeg" type="text" label="JPEG image"/>" alt="<perch:content type="text" id="alt" label="Alternate Text" help="Define alternate text for JPEG image"/>" class="<perch:content id="imageclass" type="select" label="Image Class" options="Home|image_home,Custom|image_custom,Custom 1|image_custom1,Custom 2|image_custom2,About|image_about" help="Select Image Classname" allowempty="true"/>">
</picture>
</template>
<article></article>
<script><perch:template path="upper_script.js"/></script>
as well as a Perch attribute template:
<meta property="fb:app_id" content="<perch:pages id="fbappid" type="hidden"/>">
<meta property="og:site_name" content="<perch:pages id="sitename" type="hidden"/>">
<meta property="og:url" content="<perch:pages id="url" type="hidden"/>">
<meta property="og:title" content="<perch:pages id="businessname" type="hidden"/>">
<meta property="og:description" content="<perch:pages id="og_description" label="Social description" type="textarea" escape="true"/>">
<meta property="og:image" content="<perch:content id="jpeg" type="hidden"/>">
I have managed to obtain data for all fields bar og:image
so I'm wondering how, what I am trying to do may be possible.
The response to my previous post was I believe related to this:
https://docs.grabaperch.com/perch/content/functions/content-from-multiple-pages-and-regions/
but I am not sure if that is relevant.
I can obtain content from the first four og
tags is because they are using Perch variables but regarding the last og
tag, I am wondering if PHP would need to be involved in some way.
Kind regards
Do you see your value if you use
<perch:showall />
?Your tag needs to be
perch:pages
notperch:content
.Hi Drew,
So the
perch:pages
andperch:content
namespaces are not interchangeable or compatible in any way or there is no way to use data from one namespace in another?Cheers
If you set a variable with
PerchSystem::set_var()
, you should be able to use it in any namespace.In your attributes template:
Hi Hussein,
Following is what I have first on every page:
My default.html page:
and SEO page:
The variable that I am wanting to set, will come from this .html template is is hoped:
but that being a .html template, of course comes later so would this be a reason why this might not work?
Thank you for any replies.
Yes. You need to get the image before
PerchSystem::set_vars()
and beforeperch_page_attributes()
. In other words:By the way, the SEO template you posted still uses
perch:content
. It should beperch:pages
.Also your tag
id
should be the variable name you set withPerchSystem::set_var()
. So if you usePerchSystem::set_var('image', $image_url)
, your tag should be:So when you say "region" are you referring to the outputted content via a .html template in PHP?
For the variable reference
jpeg
I have corrected but this seems irrelevant since the order of templates and regions determines what data can and cannot be reused.I believe I have the correct variable name for
<perch:pages id=""/>
but this situation is rather disappointing and while I am no developer or programmer I was of the impression that PHP could work with XMLDOM and the latter could be used anywhere in markup.You can refer to the documentation for more details on this.
This is what I have now:
in default.html there is a
<perch:pages/>
field (which it is hoped I can create a variable in PHP).then my .html template:
I don't know why this doesn't work, when it is so simple to use text from
perch_pages_navigation_text()
andperch_pages_title()
If I am doing something wrong then fine, but if it is a limitation of the system, then I guess it is not (so).
Garth, In the last line of code, what's the html template? Do you intend to call that template with
perch_content_custom
?If so, you need:
https://docs.grabaperch.com/functions/content/perch-content-custom/
A couple more things... as I just tested it to see if I could get it working...
Here's what I had to do:
I changed this:
to
I added two things: a template attribute and a
true
value.I added your
navtext
field to an attribute template calledgarth.html
and suppressed it:The reason I added the template attribute to
perch_page_attribute
was to get thenavtext
value through. I added thetrue
value to keep it from printing to the page. The reason I added thesuppress=true
to the attribute template was to keep it from outputting when you call<?php perch_page_attributes(array('template'=>'default.html'));?>
Then to get the
navtext
field to be read intoperch_page_attribute
, I needed another attribute template (garth_out.html
) that had:It seems perch can't get the field value if the field has
suppress="true"
.With that, the
set_var
worked and I had thepara
value available in my content template.The page template: