Spanish Total.js
English
Documentation For AI agents
Contents

CMS compiler

Compile pages made with the Total.js CMS editor and render them with their widgets.

.md GitHub

CMSCOMPILER(html, widgets, [used]) compiles a page made with the Total.js CMS editor. Widgets in the HTML are marked with data-cms="id__config". The compiler removes the editor markup, keeps static parts as strings and prepares widgets for rendering, so one page can be compiled once and rendered many times.

var widgets = [];

widgets.push({
    id: 'contact',
    css: '.contact{padding:20px}',
    render: function(opt, next) {
        // opt.config is the widget configuration from the editor
        next('<a href="mailto:' + opt.config.email + '">' + opt.config.email + '</a>');
    }
});

var page = CMSCOMPILER(html, widgets);
page.importcss().importjs().importmeta('<title>Contact</title>');

exports.install = function() {
    ROUTE('GET /contact/', function() {
        var $ = this;
        page.render({ url: $.url }, function(err, html) {
            $.html(html);
        });
    });
};

render(meta, [layout], [callback]) calls the widgets and builds the HTML. A widget calls next(html, [replace], [cache]); with cache its output is stored in the compiled page and reused. A layout is a compiled page with an element id="CMS"; pass it as the second argument and the page is inserted into it. Navigations (<script type="text/navigation" name="...">) and breadcrumbs (<script type="text/breadcrumb">) are Tangular templates that read meta.navigation(id) and meta.breadcrumb.

Made in Europe