ForgeTotal.js 5
it

Total.js 5

Riempire sezioni del layout da una vista

Total.js 5 · total5@0.0.19 viewslayouttemplates Eseguita con Total.js 5

Una vista può inviare markup a un punto con nome del layout. Nella vista scrivi @{section name}...@{end}; nel layout stampala con @{section('name')}. È così che una pagina aggiunge i propri script o il proprio footer senza che il layout lo sappia.

Per usare un layout diverso per una richiesta chiama $.layout('name') prima di $.view() (renderizza views/name.html come 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');
}