# Renderizzare una vista con un layout

> Renderizza una vista HTML con un modello, scorri i dati e passa valori al layout.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: it
Content-SHA256: 6cf60db29e4344e8fb4bd1190a4a451517d767c2d6ef9eb361206dc01fe1cdd1
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`$.view(name, model)` renderizza `views/<name>.html` e lo avvolge in `views/layout.html`. In una vista i dati sono disponibili come `model`; usa `@{...}` per le espressioni, `@{foreach ... in ...}` per i cicli e `@{body}` nel layout per posizionare la vista.

Il layout viene renderizzato senza il modello. Per dargli dei valori (ad esempio un titolo di pagina) usa `repository`: lo espone l'oggetto restituito da `$.view()`.

```html views/layout.html
<!DOCTYPE html>
<html>
<head><title>@{repository.title}</title></head>
<body>
@{body}
</body>
</html>
```

```html views/index.html
<h1>@{model.name}</h1>
<ul>
@{foreach item in model.items}
	<li>@{item}</li>
@{end}
</ul>
```

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

function home($) {
	var view = $.view('index', { name: 'Forge', items: ['routes', 'actions'] });
	view.repository.title = 'Home';
}
```
