ForgeTotal.js 5
en

Total.js 5

Render a view without writing a handler

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

When a route has no handler, Total.js renders a view for it: views/about.html for /about/ and views/index.html for /. You can also name the view yourself by passing a string instead of a function.

views/layout.html
<!DOCTYPE html><html><body>@{body}</body></html>
views/index.html
<h1>Home</h1>
views/about.html
<h1>About us</h1>
views/contact-page.html
<h1>Contact</h1>
controllers/default.js
exports.install = function() {
	ROUTE('GET /');
	ROUTE('GET /about/');
	ROUTE('GET /contact/', 'contact-page');
};