Forum
Using Layout Variables for blog meta
Hello,
I'm using Layout Variables to take care of the meta information on blog posts.
I have the following in my post.html template:
<perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" />
<perch:blog id="meta_description" type="textarea" label="Meta Description" suppress="true" size="xs" />
<perch:blog id="meta_keywords" type="textarea" label="Meta Keywords" suppress="true" size="xs" />
In my post.php
<?php perch_layout('global.above', array(
'title' => perch_blog_post_field(perch_get('s'), 'postTitle', true),
'meta' => perch_blog_post_field(perch_get('s'), 'meta_description', true),
'keywords' => perch_blog_post_field(perch_get('s'), 'meta_keywords', true),
));
?>
In global.above.php
<title><?php perch_layout_var('title'); ?></title>
<?php if (!perch_layout_var('page_att', true)) {
echo "<meta name='description' content='";
perch_layout_var('meta');
echo "' />";
echo "<meta name='keywords' content='";
perch_layout_var('keywords');
echo "' />";
}
?>
The Post Title is working, but not the keywords or description. I've removed 'suppress="true"' from the post.html template to make sure they are working ok there and they are.
What does this output?
'Array'
Oh! Interesting. That sounds like a bug to me. I'll get onto it.
In the meantime, it would be more efficient to make a template containing your meta tags:
and then
and
Fewer database queries, so your site will use less resources and load faster.
Thanks for coming back to me on this Drew.
I don't quite follow.
If I have a separate template file for the meta which isn't part of the post.html where can you fill in these details without a region?
Not an separate template, an additional template. Keep them in your post.html. Duplicate them in the new template for display.
Thanks for the explanation Drew.
Oddly it's now displaying the this meta template code inside the body (where the blog custom was placed inside post.php) inside quotes.
It's also just giving me the post title information and not the description and keywords like my previously.
Ok, show me what you've got.
post.html:
blog_meta.html
post.php
global.above (I know this currently would give me two <title> elements for posts)
You need to remove the
suppress="true"
fromblog_meta.html
.Ah super, these are coming through now, thank you :)
Any thoughts to why this is appearing inside the posts body rather than in the head where it's been placed in the global.above?
Nope - where is it appearing?
After some investigation the issue is the html from the blog_meta.html template is coming through with entitles:
Change
to
Thanks Drew