Page
The page object represents pages within the "Content Management" or CMS section of Evance. A "page" variable containing a Page object is automatically instantiated on URLs governed by the CMS.
A page
variable containing a Page object is automatically instantiated on CMS driven pages.
Templates for pages should be located within a Theme's
~/theme/page
directory. These templates will have access to the current page's properties
and methods described on this page.
Properties of your page can be output using the existing page variable.
<div>
<h1>{{ page.title }}</h1>
<p>{{ page.description }}</p>
</div>
Programmatically finding Pages
You can also gain access to a page and its properties from any other template programmatically.
If you need to find multiple pages you should use the PageSearch object instead - it's more efficient.
We now recommend using the new find methods when fetching a single page:
findById()
- find a page by its System ID.findByAlias()
- find a page by its Alias/URI.
The example below shows how you can find a page by its system ID.
<?ev
var myPage = new Page();
if (myPage.findById(1234)) {
print(myPage.title + ' was found');
} else {
print('Page was not found');
}
?>
Instantiation
Finding page data may be done when instantiating a new Page object and supplying the page's URL or ID. However, we now recommend using the newer 'find' methods (as described above):
<?ev
// new Page() class method
var homepage = new Page('/');
?>
Note hard coding URLs in this manner can be open to error if the URL no longer exists.
Construct parameters |
---|
reference
String |
Url |
Number
The page reference is either a String/Url representing the URL relative to root (e.g. / represents the homepage), or a Number representing the page.id. For international and multi-lingual sites you should use the default URL as the reference for the page and not the localised version. Evance will automatically correct the URL format for you once the Page object is retrieved. |
Properties |
---|
aseets
Object
An Object containing Assets for the page as defined in the Template Config. Each property within the object returned will be the same as the IDs of asset types assigned to the page template. The value of each property will be an Array containing an asset Object. Example: perhaps your homepage supports one or more banner images achieved with a slideshow asset defined in your config/templates.json file as:
The slideshow may be defined within the same file as:
|
author
Contact
Author property is null if no author is set, or as a Contact object if a valid author is set. |
averageRating
Number
The average rating out of 5 the Page has received. |
created
Date
The date the page was created represented as a Date object. |
description
String
The short description for the page represented as a String.
Pages do not have a single content block as they may have any number of editable regions. These are represented
as fragments that should be rendered via the
|
downvotes
Number
The total number of negative votes the Page has received from Users. |
expires
Date
The Date on which this page will expire, and cease to show on your website. |
id
Number
The page id represented as a Number. |
hasChildren
Boolean
A Boolean with a value of true if the page has child pages, or false if not. |
metaDescription
String
The |
metaKeywords
String
The |
metaTitle
String
The title used for the Page's |
modified
Date
The Date on which this page was last modified. |
parentId
Number
The ID for the parent page as a Number. To get the full parent page as an object use the
|
published
Date
The Date on which this page was published. Pages do not appear on your website till this date, allowing you to schedule when pages appear. |
settings
Object
An Object containing page properties defined in the Template Config and their values represented as a String. Setting property labels correlate to the id of the setting and the property value represents the value of the setting. Values can be changed by users from within the CMS editor. The best way to visualise this is with an excerpt from config/templates.json settings file for a page with properties.
...and then the resulting setting object:
|
tags
Object
Contains an object whose properties are the tag type identifiers assigned to the page's Template within the Template Config file. By default Evance supports 'tag', but you may have any number of tag types. Each property contains a TagType object. For example, tags assigned to a blog post might look like this in your
This results in page.tags having a 'tag' property containing a TagType object for a blog post, which could be accessed like this to show the TagType title and the titles of each Tag assigned to the page:
|
template
Template
References the template of this page. When printed this property will output the reference of the template, but is in fact a Template object. |
thumbnail
Url
The image Url chosen to represent this page. This is called thumbnail for historic reasons, but may be of any size. |
title
String
Contains the title of the page represented as a String. |
totalRatings
Number
The total number of ratings out of 5 the Page has received. |
upvotes
Number
The total number of positive votes the Page has received from Users. |
url
Url
The Url of the page. If you have an international website this Url will represent the current Locale of your website. |
Methods |
---|
ancestors()
PageCollection
A synonym of parents() |
archiveWithin()
Array
.. of Objects containing month and year dates of descendant pages, useful for archive representation of your blog. Each Object within the Array returned has the following properties:
|
authorsWithin()
Array
...of authors as Contact objects for all descendant pages of the current Page. This is useful for obtaining all authors within a blog, for example. Each Contact object is populated with two additional properties:
|
children([Number:limit])
PageSearch
...of child Page objects. If limit is not provided then all children are returned. The order of the children
respects the sort order available in
Please refrain from using the children() method without a limit for pages with numbers of child Page objects that would require pagination, such as Blog Posts. Such pages have other paginated mechanisms for showing child Page objects. However, obtaining the most recent Blog Post can be retrieved by supplying a limit of 1.
|
descendants()
PageSearch
All sub-pages recursively of the current Page - exclusive of the current Page. If you require a tree structure
for a menu you may like to try the |
findByAlias(String uri)
Boolean
Find a page by its unique alias/URI. Returns true if the page was found, and false if not found.
The alias supplied must be the URI path to the page (e.g. |
findById(Number id)
Boolean
Find a page by its system ID. Returns true if the page was found, and false if not found.
|
fragment(String reference)
PageFragment
| null
Returns a PageFragment object which contains the HTML content for the fragment matching the given reference. Returns |
fragments()
Object
| null
Returns an object containing all available content fragments for the page. |
hasFragment(String reference)
Boolean
Returns |
next([Number:limit])
Page
| PageCollection
| null
When no argument is provided |
parents()
PageCollection
...of this page's parent Page objects in order of closest parent first. |
prev([Number:limit])
Page
| PageCollection
| null
When no argument is provided page.prev() will return the previous sibling to the Page object, or null if
no previous sibling is available. Sound familiar? Yep, this method is the opposite to page.next(). You
guessed it, if a limit/number is provided the page.prev() method will return a PageCollection of
previous sibling pages. In either case this method respects the page.template.sort property defined in
Template Config. Which, for example, means it
is possible to show the previous three blog posts in correct sequence when on a Blog Post.
|
previous([Number:limit])
Page
| PageCollection
| null
If you have a problem with shortening names then you can use the page.previous() method instead of page.prev(), because we're considerate like that. |
relatedByTags()
PageSearch
Returns a page search object to search all pages with the same tags as the current page without any additional conditions. This allows you to find related pages from different sections of a website, but also means you will need to apply additional limits and conditions if you require to search within the current or alternative section. |
siblings()
PageCollection
... of sibling pages and respects the page.template.sort property defined within the Template Config file. |
tagsWithin()
Object
Does everything that the tags property does (above), but for all descendants of the current page recursively, excluding itself. This property is useful for blog pages where you wish to show all available tags for articles within the blog. |
topAncestor()
Page
The Page at the top of the tree for the current Page. Useful for knowing which section of a website you are within. |
tree()
PageCollection
All sub-pages recursively of and including the current Page. This is a useful property for use with menus e.g.
Notice that methods that do not require parameters may be written in property format.
|
userHasRated()
Boolean
Determines whether the current user has already rated this page.
|
userHasVoted()
Boolean
Determines whether the current user has given the current page a vote up or down.
|
userHasVotedDown()
Boolean
Determines whether the current user has given the current page a vote down.
|
userHasVotedUp()
Boolean
Determines whether the current user has given the current page a vote up.
|