ForgeTotal.js 5
en

Total.js 5

Add view helpers and read the config in views

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

Functions registered in DEF.helpers are available in every view as helpers.name(...). Use them for formatting that you repeat (prices, dates, labels).

Settings from the config file are printed with @{'%key'}, for example @{'%name'} for the name setting, so the view does not need access to 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 });
}