Spanish Total.js
English
Documentation For AI agents
Contents

Render reference

The properties of opt and the next function of exports.render.

.md GitHub
On this page

exports.render(opt, next) receives the instance and the request in opt, and gives back the content with next:

exports.render = function(opt, next) {
    next('<b>' + opt.config.name.encode() + '</b>');
};

The entries of type property are properties of opt.

API

property

opt.config

The configuration of the instance.

Returns Object

The values saved by the settings form. An instance saved before you added a key to exports.config does not have that key.

property

opt.html

The inner HTML of the instance, as saved in the page.

Returns String

It still holds the CMS_ classes of the editor.

property

opt.body

The whole instance with its wrapper, cleaned for the public page.

Returns String

property

opt.template

The <template> section of the widget.

Returns String

CLASS is already replaced. It is undefined when the widget has no template.

property

opt.id

The identifier of the instance.

Returns String

The value of data-cms-id.

property

opt.widget

The identifier of the widget.

Returns String

property

opt.url

The address of the page, such as /about-us/.

Returns String

property

opt.page

The page that is being built.

Returns Object

Its properties include id, name, title, description, keywords, url, language, layoutid and parentid.

property

opt.vars

The variables of the site, as keys and values.

Returns Object

property

opt.breadcrumb

The path from the top page to the current page.

Returns Array

An array of pages with id, url, name, title, icon and language. The first has first: true and the last has last: true.

method

opt.navigation(id)

Returns a menu of the Navigation screen.
ParameterTypeDescription
id String The identifier of the menu.

Returns Object The menu.

The menu has children (the visible links), links (all links), current (the link of the current page) and selected: true on the current link and its parents.

property

opt.mobile

true when the visitor uses a mobile device.

Returns Boolean

property

opt.robot

true when the visitor is a search engine robot.

Returns Boolean

property

opt.ua

The parsed user agent of the visitor.

Returns Object

An object with os, browser and device.

property

opt.user

The user of the request.

Returns Object

It is undefined for anonymous visitors.

property

opt.controller

The Total.js controller of the request.

Returns Object

Use it to read headers, the query or cookies of the request.

method

next(content, [replace], [cache])

Gives CMS the content of the instance.
ParameterTypeDescription
content String The HTML of the instance.
replace? Boolean true replaces the wrapper too. An empty content then removes the instance. Default: false
cache? Boolean true keeps the result until CMS builds the page again. Default: false

Call it once, also when something fails. Without replace, the content goes inside the wrapper of the instance.

Replace the instance with an import element
exports.render = function(opt, next) {
	next('<ui-import config="url:{0}"></ui-import>'.format(opt.config.url), true, true);
};
Made in Europe