# Render a view with a layout

> Render an HTML view with a model, loop over data and pass values to the layout.

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

`$.view(name, model)` renders `views/<name>.html` and wraps it in `views/layout.html`. Inside a view the data is available as `model`; use `@{...}` for expressions, `@{foreach ... in ...}` to loop and `@{body}` in the layout to place the view.

The layout is rendered without the model. To give it values (a page title, for example) use `repository`: the object returned by `$.view()` exposes it.

```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';
}
```
