- Note: Blaze templating is available only if application has
templating
andblaze
, orblaze-html-templates
packages installed.
// /imports/client/layout/layout.js
import { Template } from 'meteor/templating';
import './layout.html';
// As example all available Template's callbacks
// layout should be considered as a regular template
Template.layout.onCreated(function () { /* ... */ });
Template.layout.onRendered(function () { /* ... */ });
Template.layout.onDestroyed(function () { /* ... */ });
Template.layout.helpers({ /* ... */ });
Template.layout.events({ /* ... */ });
// /imports/client/index/index.js
import { Template } from 'meteor/templating';
import './index.html';
// As example all available Template's callbacks
Template.index.onCreated(function () { /* ... */ });
Template.index.onRendered(function () { /* ... */ });
Template.index.onDestroyed(function () { /* ... */ });
Template.index.helpers({ /* ... */ });
Template.index.events({ /* ... */ });
- Create index route
- Using
waitOn
hook wait for template to load from server - Using
action
hook to render template into layout
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
// Import layout and loading templates statically as it will be used a lot
import '/imports/client/layout/layout.js';
import '/imports/client/loading/loading.html';
// Create index route
FlowRouter.route('/', {
name: 'index',
waitOn() {
return import('/imports/client/index/index.js');
},
whileWaiting() {
this.render('layout', 'loading');
},
action() {
this.render('layout', 'index');
}
});
Introduced in v3.7.1
By default if same template is rendered when user navigates to a different route, including parameters or query-string change/update rendering engine will smoothly only update template's data. In case if you wish to force full template rendering executing all hooks and callbacks use { conf: { forceReRender: true } }
, like:
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
import '/imports/client/layout/layout.js';
FlowRouter.route('/item/:_id', {
name: 'item',
conf: {
// without this option template won't be re-rendered
// upon navigation between different "item" routes
// e.g. when navigating from `/item/1` to `/item/2`
forceReRender: true
},
waitOn() {
return import('/imports/client/item/item.js');
},
action(params) {
this.render('layout', 'item', params);
}
});