Riempire sezioni del layout da una vista
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).
<html><body>@{body}<footer>@{section('footer')}</footer></body></html><html><body class="wide">@{body}</body></html>@{section footer}
<span>Footer from the view</span>
@{end}
<h1>Home</h1>exports.install = function() {
ROUTE('GET /', home);
ROUTE('GET /wide/', wide);
};
function home($) {
$.view('index');
}
function wide($) {
$.layout('layout-wide');
$.view('index');
}