Search code examples
meteorroutesiron-router

How to split templates into separate files in Meteor


I am using Meteor.js as well as router.js (the package) in order to render other pages of my website. However, all my templates (the other pages) are in one html file. How can I split my templates into different html files and still use router.js?

One sample router configuration for a template is:

Router.route('/events', 
function(){
  this.render('eventsPage');
},
{
  onAfterAction: function() {
    document.title = 'Events';
  }
});

Where /events is the url associated with the template 'eventsPage'. How can I put the eventsPage template into a separate html file?

Thanks in advance.


Solution

  • You can have each template in separate file, Meteor detects all of your html code.

    HTML files in a Meteor application are treated quite a bit differently from a server-side framework. Meteor scans all the HTML files in your directory for three top-level elements: , , and . The head and body sections are separately concatenated into a single head and body, which are transmitted to the client on initial page load.

    Read more: http://docs.meteor.com/#/full/whatismeteor

    So your HTML file structure depends mostly on your preference.

    You should also take a look at: http://meteortips.com/first-meteor-tutorial/structure/