Blog

Using Page Attributes in Concrete5 Themes

There will times in developing a concrete5 theme when you will want or need to display a Page Attribute with the theme files.  One use of this would be to display the page name within an H1 tag at the top of each page as your page’s title.  There’s a way to do this automatically within the theme so it doesn’t have to be added to each page manually.  Here how you display Page Attributes:

Display Page Title

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

Display Page Description

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

Display Page Date

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

This displays the date in default format like this: 2009-06-15 14:09:00.
To display the date in a format like this – June 06, 2009 – use this code:

<?php echo $c->getCollectionDatePublic("F j, Y") ?>

See more about the PHP date function for other date/time formatting.

Display Any Page Attribute

<?php echo $c->getCollectionAttributeValue('attribute_name') ?>

Display a Page’s Parent Page Name

<?php
$page = Page::getByID($c->getCollectionParentID());
print $page->getCollectionName();
?>
This entry was posted in Tips. Bookmark the permalink.

15 Responses to Using Page Attributes in Concrete5 Themes

  1. ep2000 says:

    Very helpful! I haven’t seen this anywhere else and its something i’ve been looking for, Thanks!

  2. melat0nin says:

    Is it possible to show the last date a page was edited, rather than the date it went public?

  3. melat0nin says:

    Thanks Chris, but unfortunately that doesn’t work – getVersionDateCreated is an undefined method.

  4. melat0nin,
    I’d try searching the concrete5 forums or API and see what you can come up with.

  5. Just what I was looking for, thanks for this. I’m having to get up to speed with C5 fast but really enjoying it – it’s the CMS I’ve been wanting for a long time.

  6. John Steele says:

    melat0nin,

    getCollectionDateLastModified() in /concrete/models/collection.php

  7. Ron Nitzsche says:

    Cool thanks Chris.

  8. osu says:

    Hi Chris,

    Is there a tutorial somewhere (like above) on how to echo out file attributes and user attributes as well?

    I’m struggling trying to find something in the C5 api where I can print out an attribute I’ve created for an image I’ve uploaded in File Manager…

    Thanks,

    osu

  9. Pingback: Display a Page’s Grandparent Page Name | c5mix

  10. krix says:

    When I try getCollectionAttributeValue, I got Fatal error: Call to undefined method Area::getCollectionAttributeValue() in …

    I can’t find any solution.

  11. sham says:

    very helpful.. thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>