Class: Page

Basic document object used to contain the elements sent to the layout template for rendering. You can add any values you want to the object to shape your page output.

The layout property sets which template should be used to render the design of the page, unless you specify:

<?php

$page->layout = false;

?>

This will skip the layout and simply return the page body to the user.

The convention is to use the body property for the main body content.

Properties

public static $assets_version = false

If set, add the specified value as a ?v=' to the end of scripts and stylesheets that use a relative absolute path and end in.jsor.css` such as:

/apps/myapp/js/myscript.js -> /apps/myapp/js/myscript.js?v=123
/apps/myapp/css/style.css -> /apps/myapp/css/style.css?v=123

Should not affect scripts or stylesheets of these forms:

<script>...</script>
<link rel="stylesheet" href="..." />
https://www.google.com/script.js
//www.google.com/script.js?abc=123

This prevents it from altering external links including protocol-relative links, and links which are being passed parameters already.

public static $bypass_layout = false

Set this to true if you wish to globally bypass all templates. Primarily used by the async utility.

public $head = ''

Data to place in the <head> of the document. To use, add the following tag to your layouts:

{{ head|none }}

public $tail = ''

Data to place just before the closing </body> tag. To use, add the following tag to your layouts:

{{ tail|none }}

public $title = ''

The title of the page. To use, add something like this to your layouts:

{% if title %}<h1>{{ title }}</h1>{% end %}

public $_menu_title = ''

An optional separate title to be used in navigation.

public $_window_title = ''

An optional separate title to be used in the page's <title> tag.

public $body = ''

The main body of the page. To use, add the following tag to your layouts:

{{ body|none }}

public $layout = 'default'

The layout template to use to render the page.

public $scripts = array ()

A list of scripts that have been added to the page via add_script().

public $is_being_rendered = false

This is set to true when the template is currently rendering the page.

public $cache_control = false

Control caching policy for this page

public $preview = false

This is set to true when Elefant is rendering a preview request.

Methods

public __construct ()

Constructor method

public render ($tpl, $controller)

Render the page in its template and layout. Uses a Template object for rendering. Determines whether to render with a layout template at all, and if so, which one. Also determines whether to render as a preview or as a real page.

public __get ($key)

Returns title for menu_title or window_title if they're empty.

public add_script ($script, $add_to = 'head', $type = '', $integrity = '', $crossorigin = '')

Add a script to the head or tail of a page, or echo immediately if the template rendering has already begun. Tracks duplicate additions so scripts will only be added once. This makes it a good replacement for adding script include tags to view templates.

public add_style ($script, $add_to = 'head', $type = '', $integrity = '', $crossorigin = '')

Add a style to the page. Simply an alias of add_script() for the sake of referring to stylesheets correctly as styles and not scripts, but functionally they both do the same thing, and add_script() always handled stylesheets as well.

public add_meta ($name, $content = '', $attr = 'name')

Add a meta tag to the page. Example usage:

$page->add_meta ('keywords', 'One, Two, Three');
$page->add_meta ('UTF-8', '', 'charset');
$page->add_meta ('og:image', 'http://example.com/foo.jpg', 'property');
$page->add_meta ('refresh', '30;url=http://example.com/', 'http-equiv');
$page->add_meta ('<meta charset="utf-8" />');

public static wrap_script ($script, $type = '', $integrity = '', $crossorigin = '', $add_to = '')

Wrap scripts that are simply URLs in the correct HTML tags, including <link> tags for CSS files. Will pass through on scripts that are already HTML.

public static assets_version ($script = '')

Returns a script with '?v='.Page::$assets_version appended if Page::$assets_version is set and the script is a relative absolute path ending in .js or .css, otherwise it returns the script unchanged. If the script is empty, it will return