# Use conditions and escaping in views

> Branch with @{if}, @{else} and @{fi}, and choose between escaped output @{value} and raw HTML @{!value}.

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

Views are HTML with `@{...}` blocks. A condition is `@{if expression}`, optionally `@{else}`, and always closed with `@{fi}`. The expression is plain JavaScript and can use `model` (the data passed to `$.view()`), `repository` (values shared with the layout), `query`, `user`, `config` and `language`.

Output is **escaped by default**: `@{model.text}` turns `<` into `&lt;`, which protects you from injection. Put a `!` after `@{` to send the raw value (`@{!model.html}`) and do it only with content you trust.

```html views/index.html
@{layout('')}
@{if model.admin}
	<p class="role">Administrator</p>
@{else}
	<p class="role">Guest</p>
@{fi}
@{if model.items.length > 2}
	<p class="many">many items</p>
@{fi}
<div class="escaped">@{model.text}</div>
<div class="raw">@{!model.text}</div>
```

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

function page($) {
	$.view('index', { admin: $.params.role === 'admin', items: [1, 2, 3], text: 'Hello <b>World</b>' });
}
```
