Introduction

anomaly.module.pages

The Pages module let's you create and manage structured page content and automatically generate navigation from it too!

Features

The Pages module comes with everything you need to manage and display rich structured content.

  • Drag and drop UI
  • Automated navigation generation
  • Multiple page types with custom fields and layout
  • Powerful page handlers for extending behavior

Installation

You can install the Pages module with the addon:install command:

php artisan addon:install anomaly.module.pages
Notice: The Pages module comes installed with PyroCMS out of the box.

Usage

This section will show you how to use the addon to build and deliver rich structured content.

Types

Page types are allow you to define custom fields and layout for pages of this type.

Fields

Below is a list of fields in the types stream. Fields are accessed as attributes:

$type->name;

Same goes for decorated instances in Twig:

{{ type.name }}
Fields
Key Type Description

name

text

The type name.

description

textarea

The type description.

slug

slug

The slug used for API and database table.

handler

addon

The page handler extension to use.

theme_layout

select

The default theme layout for pages of this type.

layout

editor

The layout of the custom page fields.

Theme Layouts

The type's theme layout will define the defualt theme layout to wrap the page's content.

Theme layouts generally specify the top level structural layout of your website. Perhaps a layout for your home page specifically, one for two column pages, and perhaps one custom HTML pages.

Accessing Active Pages

You can access the active page in theme layouts if needed by using the template super variable.

{{ template.page.title }}

A more realistic example might look like this:

{% if template.page.banner_image.id %}
    <div id="banner" style="background-image: url({{ template.page.banner_image.path }});">
        ...
    </div>
{% endif %}

Page Layouts

The type's page layout is wrapped by the theme layout.

The primary goal of the page layout is to display the page's custom field values.

Defining Page Layouts

When defining the page layout the page is available to access field values.

In the simple example below content is the field slug of the WYSIWYG field assigned to this page's type.

<h1>{{ page.title }}</1h>

{{ page.content.render|raw }}

A more powerful example using our Grid field type with the field slug content might look like this:

{% for section in page.content %}
    <div class="section {{ section.type }}-section-type">
        {% include "theme::sections/" ~ section.type %}
    </div>
{% endfor %}

The above example will let you define well designed and controlled content section that allow the user to easily build structured stacks of content.

Pages

Pages are the primary components of your structured content. Every page has a type that defines it's available fields and layout.

Fields

Below is a list of fields in the pages stream not including custom fields.

Fields are accessed as attributes:

$page->title;

Same goes for decorated instances in Twig:

{{ page.title }}

Note that active pages get pushed into the template super variable:

{{ template.page.title }}
Fields
Key Type Description

title

text

The display title.

slug

slug

The path slug.

meta_title

text

The meta title falls back to the page title.

meta_description

textarea

The meta description.

meta_keywords

tags

The meta keywords.

enabled

boolean

Whether the page is enabled or not.

home

boolean

Whether the page is the home page or not.

visible

boolean

Whether to display the page in structure() navigation or not.

exact

boolean

Whether to require an exact URI match or not.

allowed_roles

multiple

The user roles allowed to view the page.

theme_layout

select

The theme layout to override the value defined in the page's type.

Plugin

This section will go over how to use the plugin that comes with the Pages module.

structure

The structure function let's you generate navigation structure based on your pages structure.

The returned plugin criteria will render the resulting navigation automatically using __toString() if you do not explicitly call render().

Returns: \Anomaly\Streams\Platform\Addon\Plugin\PluginCriteria
Arguments
Key Required Type Default Description

$root

false

mixed

none

The id, instance, or path of the root navigation page.

Twig
{{ structure()|raw }}

{# Showing child page navigation #}
{{ structure(template.page)
    .linkAttributesDropdown({'data-toggle': 'dropdown'})
    .listClass('nav navbar-nav navbar-right')
    .childListClass('dropdown-menu')
    .render()|raw }}
Available Options

The structure uses the plugin criteria to allow you to configure options for the resulting navigation.

Options are defined by chaining together camelCase methods:

{{ structure().optionOne('example')|raw }} // Results in option_one = example

So to define dropdown_class for example you would do this:

{{ structure().dropdownClass('dropdown')|raw }}
Pro Tip: Defining criteria options this way is standard throughout Pyro!
Options
Key Required Default Description

view

false

anomaly.module.pages::structure

The base view to render the navigation from.

macro

false

anomaly.module.pages::macro

The macro to use for rendering the navigation.

depth

false

none

The maximum depth of the navigation.

list_tag

false

ul

The list tag to use.

list_class

false

none

The list class to use.

item_tag

false

li

The list item tag to use.

dropdown_class

false

dropdown

The CSS class for links containing child links.

active_class

false

active

The CSS class for links that are selected or whose child link is selected.

selected_class

false

current

The CSS class for the currently selected navigation link.

link_class

false

none

The CSS class to use for links.

link_attributes

false

[]

An array of key value html attributes for links.

link_attributes_dropdown

false

[]

An array of key value html attributes for links that have a dropdown.

child_list_tag

false

list_tag

The list tag for child lists.

child_list_class

false

none

The list class for child lists.

dropdown_toggle

false

none

The dropdown toggle tag to use in the case a dropdown toggle is desired.

dropdown_toggle_class

false

none

The dropdown toggle class to use in the case a dropdown toggle is desired.

dropdown_toggle_attributes

false

[]

An array of key value html attributes for the dropdown toggle.

dropdown_toggle_text

false

none

The text or HTML to display inside the dropdown toggle.

page

The page function returns the decorated instance of the desired page.

Returns: \Anomaly\PagesModule\Page\PagePresenter or null
Arguments
Key Required Type Default Description

$identifier

false

mixed

Current page

The id or path of the desired page.

Twig
<a href="{{ page('about/company').route('view') }}"></a>

{# Displaying page content #}
{{ page('about/contact').content()|raw }}

Extensions

This section will go over the extensions available for extending the behavior of the Pages module.

Handlers

Page handler are an extension that let you extend the behavior of pages.

For example you could use a URL Page Handler to change the UI for the page into that of a simple redirect. This will prevent you from having to use the Navigation module for a simple off-site link or top level navigation item.

Another example could be a GitHub Page Handler that pulls it's content from a github repository to allow collaboration on it. Where all the user has to do is define the source file.