ForgeTotal.js 5
fr

Total.js 5

Remplir des sections du layout depuis une vue

Total.js 5 · total5@0.0.19 viewslayouttemplates Exécutée avec Total.js 5

Une vue peut envoyer du balisage vers un emplacement nommé du layout. Dans la vue, écrivez @{section name}...@{end} ; dans le layout, affichez-la avec @{section('name')}. C'est ainsi qu'une page ajoute ses propres scripts ou son pied de page sans que le layout le sache.

Pour utiliser un autre layout pour une requête, appelez $.layout('name') avant $.view() (cela rend views/name.html comme 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');
}