ForgeTotal.js 5
it

Total.js 5

Aggiungere helper di vista e leggere la config nelle viste

Total.js 5 · total5@0.0.19 viewstemplatesconfig Eseguita con Total.js 5

Le funzioni registrate in DEF.helpers sono disponibili in ogni vista come helpers.name(...). Usale per formattazioni che ripeti (prezzi, date, etichette).

Le impostazioni del file config si stampano con @{'%key'}, per esempio @{'%name'} per l'impostazione name, così la vista non ha bisogno di accedere a CONF.

config
name : Forge shop
definitions/helpers.js
DEF.helpers.price = function(value) {
	return '$' + value.toFixed(2);
};
views/index.html
@{layout('')}
<h1>@{'%name'}</h1>
<p class="price">@{helpers.price(model.price)}</p>
controllers/default.js
exports.install = function() {
	ROUTE('GET /', page);
};

function page($) {
	$.view('index', { price: 9.5 });
}