ForgeTotal.js 5
ro

Total.js 5

Randarea unei vizualizări cu un layout

Total.js 5 · total5@0.0.19 viewslayouttemplates Executată cu Total.js 5

$.view(name, model) randează views/<name>.html și o înfășoară în views/layout.html. Într-o vizualizare datele sunt disponibile ca model; folosește @{...} pentru expresii, @{foreach ... in ...} pentru bucle și @{body} în layout ca să plasezi vizualizarea.

Layout-ul este randat fără model. Ca să-i dai valori (de exemplu un titlu de pagină), folosește repository: îl expune obiectul returnat de $.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';
}