Generally, the architecture behind concrete5 is
- Blocks are the smallest amount of visible content available.
- Areas contain these blocks.
- Areas are contained within Collection Versions
- Collection Attributes are assigned to Collection Versions
- Collection Versions are contained within Collections
- Pages extend Collections, turning Collections into something viewable from the front-end.
- Pages can either be of a certain page type, or a one-off page (single page).
This is why the currently rendered page is typically available as the $c object - it was originally referred to as a Collection object. In practice, the line between Collection and Page is very fuzzy, to the point where developers would be well served by working simply with Page objects, which extend the Collection object anyway.
Working with the current page
Throughout your code, if you wish to grab the object for the currently rendered page, simply execute this code:
$page = Page::getCurrentPage();
This will return the currently rendered page's object.
Adding a page of a certain type under another page
$parentPage = Page::getByPath("/sample"); $data = array( 'name' => "sample2", 'cHandle' => "sample2handle", 'cDescription' => "Add page test." ); $pt = CollectionType::getByHandle("page_type_handle"); $newPage = $parentPage->add($pt,$data);
Getting a Page Object by ID or Path
$page = Page::getByPath('/path/to/page', $version = 'RECENT');
Returns the current page based on its page path. $version determines which CollectionVersion object to load within the Page object. Valid values are
- 'recent' - loads the recent version
- 'active' - loads the currently approved, active version
- a numerical ID - loads the version by its $cvID
$page = Page::getByID($pageID, $version = 'RECENT');
Same as getByPath, but loads based on the numerical $cID.
Page Object Methods
While the Page (and Collection) objects have a lot of methods, you probably will only need to work with a few:
Returns the page's ID.
Returns the user ID of the page (typically the initial creator of the page, or page's owner if it has been changed through the Page Properties overlay.)
Returns the page's handle.
Returns the ID of the page's collection type.
Returns the handle of the page's collection type.
$pageTheme = $page->getCollectionThemeObject()
Returns the PageTheme object of the page's current theme.
Returns the name of the current page. Queries the currently loaded version object for this information.
Returns the description of the current page. Queries the currently loaded version object for this information.
$page->getCollectionDatePublic($dateFormat = null, $type = 'system')
Gets the public date for a page. $dateFormat is a PHP date() string. $type may also be 'user' if ENABLE_USER_TIMEZONES is set to true. (Note: this date is the date changeable through the properties overlay.)
Gets the ID of this page's parent page. Every page has a parent, with the exception of the home page and master collections.
Returns true if the currently accessed page is a master page (accessed through Dashboard > Pages > Page Types)
Gets the current sitemap display order of a page.
Gets the number of children directly beneath a page.
$page->getFirstChild($sortColumn = 'cDiaplyOrder asc')
Returns the first child of the current page, or null if there is no child.
Returns the display value of an attribute when passed an attribute key handle.
$page = Page::add(CollectionType $pageType, $data)
Adds a new page of type $pageType, setting the various provided fields in the $data array. This array may contain:
- "uID": User ID of the page's owner
- "pkgID": Package ID the page belongs to
- "cName": The name of the page
- "cHandle": The handle of the page as used in the path
- "cDatePublic": The date assigned to the page
Updates a page, and takes the same $data array as above.
Moves a page to a new location in the site.
Copies a page to a new location in the site.
Deletes a page, INCLUDING ALL CHILDREN.
Sets the current theme of a page.
Sets an attribute against a page. $ak may either be an instance of the CollectionAttributeKey object, or a Collection Attribute handle.
Clears an attribute against a page. $ak may either be an instance of the CollectionAttributeKey object, or a Collection Attribute handle.
Working with Blocks
$page->addBlock(BlockType $bt, Area $a, $data)
Adds a block of a certain type to a specific area, providing a $data array (which is then passed to the block's controller save() function.) For more information on this function, consult the developer documentation on blocks.
$blocks = $page->getBlocks($areaHandle = false)
Returns an array of generic Block objects found on a page. If $areaHandle is provided, only those blocks in that area will be passed back.