ForgeTotal.js 5
de

Total.js 5

Abschnitte des Layouts aus einer View füllen

Total.js 5 · total5@0.0.19 viewslayouttemplates Mit Total.js 5 ausgeführt

Eine View kann Markup an eine benannte Stelle des Layouts schicken. Schreibe in der View @{section name}...@{end}; im Layout gibst du ihn mit @{section('name')} aus. So fügt eine Seite eigene Skripte oder einen Footer hinzu, ohne dass das Layout davon weiß.

Um für eine Anfrage ein anderes Layout zu nutzen, rufe $.layout('name') vor $.view() auf (es rendert views/name.html als 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');
}