---
title: CMS compiler
project: Total.js V4
version: 0.0.99
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/guides/cms/
updated: 2026-11-16T15:41:10.817Z
---

# CMS compiler

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

`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.

```js
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`.
