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?

jgarcia
 
jgarcia replied on at Permalink Reply
jgarcia
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
ryan
Here's how you get the attribute value from withing a template:
<?
Loader::model('collection_attributes');
$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
ryan
Yeah, I forgot you can pass in the handle, that makes it much easier