Using page attributes in a template

Permalink 5 users found helpful
I am trying to create a template in which the page title (meta_title) is automatically be displayed in an H1 tag. How can you use page attributes in a template? Or is there a better way to do this?

View Replies:
jgarcia replied on at Permalink Reply
Well, I'll try to be more patient and spend a little more time researching before posting here. Here is the solution I found to display the page name to display within a template. Simply add:

<?php echo $c->getCollectionName() ?>

This will display the page name, but it call also be done with other page attributes, simply by using:

<?php echo $c->getCollectionAttributeValue('attribute_name') ?>
ryan replied on at Permalink Reply
Here's how you get the attribute value from withing a template:
$ak = CollectionAttributeKey::getByHandle('meta-description');
$value = $c->getCollectionAttributeValue($ak);
echo $value;

It seems like a bit too much work & there may be a simpler way to do it..
ryan replied on at Permalink Reply
Yeah, I forgot you can pass in the handle, that makes it much easier