LemonStand Documentation

Cms_Page

The Cms_Page class represents a LemonStand page. A reference to the current page is always available through the controller's $page field and can be accessed from any page, template or partial code in the following manner: $this->page.

Parent class: Db_ActiveRecord

Class fields

  • $title – a title of the page. You specify the title when you create a page in the Page Editor.
  • $url – an URL of the page
  • $description – the page description. You can assign a description to the page in the Page Editor.
  • $keywords – the page keywords. You can assign keywords to the page in the Page Editor.
  • $navigation_visible - indicates whether the page should be visible in the site maps or menus. You can manage this field value on the Navigation tab of the Create/Edit Page form.
  • $navigation_label - specifies a page navigation label, which you assigned on the Navigation tab of the Create/Edit Page form.
  • $content - page content code. The HTML code which you edit in the Create/Edit Page form. Important! This field contains non-processed PHP code. If you need to obtain a page content with all PHP code evaluated, use the content_by_url() method described below.

Usually you need to access the page object fields to output a page title, description and keywords inside a page template's HEAD element: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title><?= h($this->page->title) ?></title>
  <meta name="Description" content="<?= h($this->page->description) ?>"/>
  <meta name="Keywords" content="<?= h($this->page->keywords) ?>"/>
  <?= include_resources() ?>
</head>
<body>
  ... 

Class methods

  • navigation_root_pages() - returns a list of root pages. Root pages are those pages for which you haven't specified a parent page on the Navigation tab of the Create/Edit Page form. The method returns an array of Cms_PageNavigationNode objects (see the description below).
  • navigation_label() - returns the navigation menu label, assigned to the page on the Navigation tab of the page edit form. If the navigation menu label was not assigned for the page, the method will return the page title.
  • navigation_subpages() - returns a list of subpages grouped under this page. Returns an array of Cms_PageNavigationNode objects.
  • navigation_parents($include_this_page = true) - returns a list of the page parents. You can use this method for generating bread crumb navigation. The method returns an array of the Cms_PageNavigationNode objects.
  • find_by_url($url, &$params) - static method. Returns a page object by the page URL. The second parameter is reserver for the system needs. Pass an array-typed variable into it. Example:
    $params = array();
    $page = Cms_Page::findByUrl('/your-page-url', $params);
  • content_by_url($url) - static method. Returns an evaluated page content. The returned value does not contain the page template markup. It contains only the page content, including values of any content blocks defined on the page. Example:
    echo Cms_Page::content_by_url('/sidebar');

About the Cms_PageNavigationNode class

The Cms_PageNavigationNode class is a placeholder object which holds information about a specific page. It is used during the dynamic menus generation instead of the Cms_Page class in order to save server memory. This class has methods and fields sufficient for building menus. In most cases, during the menu generation process, you can work with objects of this class as if you were working with Cms_Page objects. This class has the following fields:

  • $id - page identifier
  • $title - page title
  • $url - page URL
  • $navigation_visible - indicates whether the page should be visible in the site maps or menus. You can manage this field value on the Navigation tab of the Create/Edit Page form.
  • $navigation_label - specifies a page navigation label, which you assigned on the Navigation tab of the Create/Edit Page form.

Loading the content of a content block

If you have a content block defined on a page, you can load its content using the API. First, you need to find the page itself by its URL. Then you need to find the content block by its code. Example:

$a = array();
$page = Cms_Page::findByUrl('/sidebar',$a);
$content_block = Cms_ContentBlock::get_by_page_and_code($page->id, "content");
echo $content_block->content;

See also:

Next: Shop_BundleItemProduct
Previous: Cms_Controller
Return to Reference

Comments

Peter Crouch

Thursday, November 25, 2010

Someone else might find this useful - it recursively builds a menu to the specified limit.

<ul <?= isset($id)?"id=\"$id\"":NULL; ?> class="menu<?= isset($class)?" $class":NULL; ?>">
<?
$parents = isset($parents)?$parents:Cms_Page::navigation_root_pages();
$limit = isset($limit)?$limit:4;
$depth = isset($depth)?++$depth:2;// track recursion depth

$end = count($parents)-1;
$half = $end / 2;
foreach ​($parents as $index=>$parent) :
$children = $parent->navigation_subpages();
switch ($index) {
case 0:
$class="start";
break;
case $half:
$class="half";
break;
case $end:
$class="end";
break;
default:
$class = "";
}
?>
<li class="<?= $class ?>"><a href="<?= $parent->url ?>"><?= h($parent->navigation_label()) ?></a><?= ($depth<= $limit && count($children))?$this->render_partial('site:menu',array('parents'=>$children,'limit'=>$limit,'depth'=>$depth,'class'=>"child child$depth")):NULL; ?></li>
<? endforeach;
?>
</ul>

Add your comment

Loading form...