ForgeTotal.js 5
en

Total.js 5

Fill sections of the layout from a view

Total.js 5 · total5@0.0.19 viewslayouttemplates Executed against Total.js 5

A view can send markup to a named place of the layout. In the view write @{section name}...@{end}; in the layout print it with @{section('name')}. This is how a page adds its own scripts or footer without the layout knowing about it.

To use a different layout for a request call $.layout('name') before $.view() (it renders views/name.html as the layout).

views/layout.html
<html><body>@{body}<footer>@{section('footer')}</footer></body></html>
views/layout-wide.html
<html><body class="wide">@{body}</body></html>
views/index.html
@{section footer}
	<span>Footer from the view</span>
@{end}
<h1>Home</h1>
controllers/default.js
exports.install = function() {
	ROUTE('GET /', home);
	ROUTE('GET /wide/', wide);
};

function home($) {
	$.view('index');
}

function wide($) {
	$.layout('layout-wide');
	$.view('index');
}