Download the PHP package icybee/module-pages without Composer
On this page you can find all versions of the php package icybee/module-pages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package module-pages
Pages
The Pages module (pages
) introduces the "Page" content type to the CMS
Icybee. Pages are used to created the website tree, display contents and
views. The module provides a request dispatcher to serve the pages it manages.
Blueprint
A blueprint is a simplified data structure representing the relationship between pages. It
provides child/parent relations, parent/children relations, an index, and a tree representation.
The blueprint can be created from a Query or can be obtained from the pages
model.
The following properties are available:
relations
: Child/parent relations, key to key.children
: Parent/children relations, key to key.index
: The blueprint nodes, indexed by key.tree
: The blueprint nodes, nested in a tree.model
: The model associated with the blueprint.
Obtaining a blueprint from a query
The following example demonstrates how a blueprint can be obtained from a Query instance. Only
the nid
and parent_id
properties are required to build the bulueprint, but you might want
more than that to be useful. In the example, the blueprint is created with the additional
properties slug
and pattern
:
Obtaining a blueprint from the model
A blueprint can be obtained from the pages
model. This blueprint is often used to compute
navigation or resolve routes. It is created with the additional properties is_online
,
is_navigation_excluded
, and pattern
.
Note: This blueprint is cached, that is two calls to the blueprint()
method with the same
argument yield the same instance. If you require to modify the blueprint itself you are advised to
use a clone.
Obtaining a subset of a blueprint
A subset can be created from a blueprint, this is interesting when you wish to work with a particular branch, or only the nodes that have a maximum depth of 2, or maybe only the online nodes.
The following example demonstrates how a subset of a blueprint with only the branch of a particular branch can be obtained:
The following example demonstrates how a subset of a blueprint with nodes that have a maximum depth of 2 can be obtained:
The following example demonstrates how a subset of a blueprint with only the online nodes can be obtained using a closure:
Populating a blueprint
Once you have obtained a blueprint you might want to populate it with actual records. The
populate()
method populates a blueprint by loading the associated records, and updates the
blueprint nodes with them. Don't worry about performance, the records are obtained with a single
query through the find()
method of the model, and benefit from its caching mechanisms.
Obtening and ordered array of nodes or records
Through the ordered_nodes
and ordered_records
read-only properties you can obtain an array of
nodes or records. They are ordered according to their weight and relation.
Traversing a blueprint
The index
of the blueprint holds all of its nodes in a flat array. The order is non important.
The following example demonstrates how to traverse a blueprint using its index:
The navigation element
The NavigationElement class makes it very easy to render a navigation element from a blueprint.
Will render something like this (prettyfied for lisibility):
Before the navigation element is populated with children
The event Icybee\Modules\Pages\NavigationElement::populate:before
of class BeforePopulateEvent is fired before the navigation element is populated with children.
Third parties may use this event to alter the blueprint. For instance, using a subset instead of the complete blueprint.
The following code demonstrates how the node with id "5" is discarded from the navigation:
After the navigation element was populated with children
The event Icybee\Modules\Pages\NavigationElement::populate
of class PopulateEvent is fired after the navigation element was populated with children.
Third parties may use this event to alter the renderable elements of the navigation. For instance, one can replace links, classes or titles.
The following example demonstrates how to alter the href
and target
attributes of
navigation links:
Rendering pages
Page instances are rendered using a PageRenderer instance. This is usually handled by the PageController, but sometimes you might want to do that yourself, without being required to dispatch a request, for example when rendering a Page instance that you have created yourself.
Events are fired before and after the rendering, allowing third parties to alter the rendering.
The module also provides a default renderer that is used when rendering a Page instance to a
HTML string with either the render()
prototype method, or __toString()
.
You can override the render()
method to use your own renderer:
Before the rendering
The event Icybee\Modules\Pages\PageRenderer::render:before
event of class BeforeRenderEvent
is fired before the page is rendered. Third parties may use this event to alter the rendering
context, or the assets of the document.
After the rendering
The event Icybee\Modules\Pages\PageRenderer::render
event of class RenderEvent is fired
after the page was rendered. Third parties may use this event to alter the HTML string produced.
The inject()
method is used to insert a HTML fragment relative to an element in the produced
HTML. The following example demonstrates how the content of a $fragment
variable can be injected
at the bottom of the BODY
element.
The replace()
method is used to replace a placeholder by a HTML fragment.
Prototype methods
Icybee\Modules\Sites\Site::lazy_get_home
The home
getter is added to instances of Icybee\Modules\Sites\Site
. It returns the home
page of the instance:
ICanBoogie\Core::get_page
The page
getter is added to instances of ICanBoogie\Core
. It returns the page currently being
displayed. The getter is a shortcut to $app->request->context->page
.
Patron markups
The following Patron markups are defined by the module:
p:breadcrumb
p:navigation
p:navigation:leaf
p:page:content
p:page:languages
p:page:region
p:page:title
The p:navigation
markup
Navigation elements for the current page are rendered with the p:navigation
markup.
The CSS class names to use by the navigation branch can be specified with the css-class-names
parameter. The default is "'-constructor -slug -template'", which removes the constructor, slug,
and template names. The maximum depth of the navigation is specified by the depth
parameter.
The starting level of the navigation is specified by the from-level
parameter. Using the
min-children
parameter, navigation branches can be discarded if they don't include enough
direct children. Finally, the parent
parameter can be used to specify the parent of the
navigation, which can be specified as a Page instance, an identifier, or a path.
The template is published with a NavigationElement instance as thisArg.
The p:navigation:leaf
markup
Render a navigation leaf from the current page.
css-class-name
specifies the modifiers to use to generate the CSS classes of the header
and the content nodes. It defaults to "active trail id". depth
is the maximum depth of the
branch. It defaults to 2.
The template is published with a NavigationBranchElement instance as thisArg.
Requirement
The package requires PHP 5.5 or later.
Installation
The recommended way to install this package is through Composer:
Cloning the repository
The package is available on GitHub, its repository can be cloned with the following command line:
$ git clone https://github.com/Icybee/module-pages.git pages
Testing
The test suite is ran with the make test
command. Composer is
automatically installed as well as all the dependencies required to run the suite. The package
directory can later be cleaned with the make clean
command.
The package is continuously tested by Travis CI.
Documentation
The documentation for the package and its dependencies can be generated with the make doc
command. The documentation is generated in the docs
directory using ApiGen.
The package directory can later by cleaned with the make clean
command.
License
This package is licensed under the New BSD License - See the LICENSE file for details.
All versions of module-pages with dependencies
icanboogie/module-installer Version ^1.2
icanboogie/bind-render Version ^0.5
icybee/module-nodes Version ^3.0