Sitemap
Describe the pages of a website in the sitemap file and use it for navigation and breadcrumbs.
The file sitemap in the root of the application describes the pages of a website. Each line is id : title --> url --> parent:
// sitemap
homepage : Homepage --> /
products : Products --> /products/ --> homepage
detail : {0} --> /products/{0}/ --> products
contact : @(Contact) --> /contact/ --> homepageLines that start with # or // are comments. @(...) around a title or URL translates it with the localization resources. {0} is a placeholder that you fill later, and a URL that ends with * is a wildcard.
A route can use the ID instead of the URL. Without an action, the route renders the view with the name of the ID (index for /):
exports.install = function() {
ROUTE('#homepage');
ROUTE('#products', 'products/list');
ROUTE('GET #detail', detail);
};
function detail(id) {
this.sitemap();
this.sitemap_change('detail', 'name', 'Product ' + id);
this.view('products/detail');
}#id also works in WEBSOCKET(), MERGE(), MAP() and LOCALIZE(). A route with an unknown ID throws an error.
For an ID route with a view name or no action, the framework loads the breadcrumb itself; in your own action call this.sitemap(). It also sets the page title to the name of the current item. Views read the breadcrumb as sitemap:
<ol class="breadcrumb">
@{foreach m in sitemap}
<li><a href="@{m.url}">@{m.name}</a></li>
@{end}
</ol>
<a href="@{sitemap_url('detail', model.id)}">@{sitemap_name('products')}</a>SITEMAP(id) returns the breadcrumb outside a controller, and F.sitemap_navigation(parent) the items with one parent, for menus.