# Fill sections of the layout from a view

> Declare a section in a view with @{section} and print it in the layout with @{section('name')}, and pick another layout per request.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 7141532df90da0c4a7379b60398902258ee91cf9be67a8060622d2fb6d40b7c0
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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).

```html views/layout.html
<html><body>@{body}<footer>@{section('footer')}</footer></body></html>
```

```html views/layout-wide.html
<html><body class="wide">@{body}</body></html>
```

```html views/index.html
@{section footer}
	<span>Footer from the view</span>
@{end}
<h1>Home</h1>
```

```js controllers/default.js
exports.install = function() {
	ROUTE('GET /', home);
	ROUTE('GET /wide/', wide);
};

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

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