ForgeTotal.js 5
en

Total.js 5

Include views and assets

Total.js 5 · total5@0.0.19 viewstemplatesassets Executed against Total.js 5

@{view(name, model)} renders another view in place, so repeated pieces (a card, a row, a footer) live in one file. The second argument is the model of the included view.

@{import('a.js', 'a.css')} writes the <script> and <link> tags for files in public/js/ and public/css/. List several files joined with + to get one tag per file.

views/card.html
<article class="card"><h2>@{model.title}</h2></article>
views/index.html
@{layout('')}
@{import('app.js', 'app.css')}
@{foreach item in model.items}
	@{view('card', item)}
@{end}
controllers/default.js
exports.install = function() {
	ROUTE('GET /', page);
};

function page($) {
	$.view('index', { items: [{ title: 'First' }, { title: 'Second' }] });
}