Getting Data about a Page

Built-In Properties

The following are some of the built-in properties always available about a page, and how to retrieve them.

Retrieve a page's name

print $c->getCollectionName();

Get its short description

print $c->getCollectionDescription();

Get the canonical date the page was created

print $c->getCollectionDateAdded();

Get the publicly changeable date (useful for treating pages like blog objects.)

print $c->getCollectionDatePublic();

Get the User ID of the page's owner

print $c->getCollectionUserID();

Custom Attributes

It's also easy to retrieve a custom attribute about a page.

$response = $c->getAttribute('attribute_handle');

The $response in this case will be the standard response based on the type of attribute. Sometimes this will be simple:

$response = $c->getAttribute('exclude_nav');

Since The Exclude from Navigation attribute is a boolean attribute, $response will either be true or false.

$response = $c->getAttribute('thumbnail');

The Elemental Full installation of sample content creates a "thumbnail" attribute of the image/file type. If this attribute is present for the page, the $response will actually be either null or an instance of the Concrete\Core\File\File object.

Return Presentable Data

Custom attributes types can return their data in ways that are meant to be presented to the end user. While the custom getAttribute() call returns the data in its mode programmatic state (e.g. returning file objects, address objects, etc…) it's easy to return the data in such a way that it can be quickly printed out to the end user.

$response = $c->getAttribute('thumbnail', 'display');

This will return the thumbnail attribute using the image/file attribute types getDisplayValue() method, which returns an HTML link.


Here's an example taken from a theme's page template, that lists all the tags on a page, and makes it easy to link to them in a search interface.

    $tags = $c->getAttribute('tags');
    if ($tags && count($tags)) { ?>
        <div class="tags">
            <div class="title"><span>Tags</span></div>

                <? foreach($tags as $tag) { ?>
                    <li><a href="<?=URL::page($blog, 'tag', strtolower($tag))?>"><?=$tag?></a></li>
                <? } ?>
    <? }

Checking if in Edit Mode

It's easy to check to see if the page is currently being edited by a user.

if ($c->isEditMode()) {


Retrieving all Blocks Objects on a Page.

$blocks = $c->getBlocks();

Retrieving all Blocks Objects from an Area on a Page.

$blocks = $c->getBlocks('Area name');
$blockIDs = $c->getBlockIDs('Area name');

Retrieving an Area Object on a Page.

$area = $c->getArea('Area name');

Page API

There are many, many more operations available on the page object. Check out the API documentation.

\Concrete\Core\Page\Page API Reference

Loading Conversation