Forum
set_vars in layout
I'm having some issues with the set_var(s) when using them in a layout.
At the moment I am using them in my global header, which I am using to pass info into my perch_page_attributes(); tag.
The issue I am finding is that it works on both pages (I only have two pages on the site) for a refresh or two. Then will only work on one page after that.
If I change the id of the set_vars they begin to work again but after a while revert back to only working on one page.
I'm wondering if this is a bug or I'm doing somthing wrong.
Here is the code (snippet) in the global.header layout file
$domain = 'https://'.$_SERVER["HTTP_HOST"];
$url = $domain.$_SERVER["REQUEST_URI"];
$sitename = perch_pages_title(true);
PerchSystem::set_var('siteDomain', $domain);
PerchSystem::set_var('pageURL', $url);
PerchSystem::set_var('pageName', $sitename);
perch_page_attributes();
And here is the code of my attribute template
<!-- Twitter Card data -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="<perch:pages type="text" id="twitter-account" label="Twitter Account" help="e.x @gemagency" divider-before="Info for when someone shares site on Twitter" />">
<meta name="twitter:title" content="<perch:pages id="pageName" type="hidden" />">
<meta name="twitter:description" content="<perch:pages id="pageDescription" striptags="true" type="hidden" />">
<meta name="twitter:creator" content="<perch:pages type="text" id="twitter-account" />">
<!-- Twitter Summary card images must be at least 120x120px -->
<meta name="twitter:image" content="<perch:pages id="siteDomain" type="hidden" /><perch:pages id="twitter-image" type="image" width="120" height="120" crop="true" label=" Twitter share image" />">
<meta name="twitter:url" content="<perch:pages id="pageURL" type="hidden" />" />
<!-- Open Graph (facebook) data -->
<meta property="og:title" content="<perch:pages id="pageName" type="hidden" />" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<perch:pages id="pageURL" type="hidden" />" />
<meta property="og:image" content="<perch:pages id="siteDomain" type="hidden" /><perch:pages type="image" id="facebook-image" label="Facebook Image" divider-before="Info for when someone shares site on Facebook" />" />
<meta property="og:description" content="<perch:pages id="pageDescription" striptags="true" />" />
<meta property="og:site_name" content="<perch:pages id="pageName" type="hidden" />" />
You can see the outcome on the links below, the code is the same but the info is missing on the homepage.
https://gem-agency.com/contact
Any thoughts?
You can do the same with
perch_page_attributes_extend()
- does that work?That's seems to have done the trick thanks! Much more stable now.
Might be worth noting that perch_page_attributes_extend needs to be used in conjunction with perch_page_attributes to output the attributes on the docs page.
Thanks again!