ForgeTotal.js 5
sk

Total.js 5

Vykresli view s layoutom

Total.js 5 · total5@0.0.19 viewslayouttemplates Spustené s Total.js 5

$.view(name, model) vykreslí views/<name>.html a obalí ho do views/layout.html. Vo view sú dáta dostupné ako model; použi @{...} pre výrazy, @{foreach ... in ...} pre cyklus a @{body} v layoute na umiestnenie view.

Layout sa vykresľuje bez modelu. Ak mu chceš poslať hodnoty (napríklad titulok stránky), použi repository: sprístupňuje ho objekt, ktorý vracia $.view().

views/layout.html
<!DOCTYPE html>
<html>
<head><title>@{repository.title}</title></head>
<body>
@{body}
</body>
</html>
views/index.html
<h1>@{model.name}</h1>
<ul>
@{foreach item in model.items}
	<li>@{item}</li>
@{end}
</ul>
controllers/default.js
exports.install = function() {
	ROUTE('GET /', home);
};

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