Book Image

Building Single-page Web Apps with Meteor

By : Fabian Vogelsteller
Book Image

Building Single-page Web Apps with Meteor

By: Fabian Vogelsteller

Overview of this book

Table of Contents (21 chapters)
Building Single-page Web Apps with Meteor
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Changing the website's title


Now that we have the routes of our posts working, we are only missing the right titles being displayed for each page.

Sadly, <head></head> is not a reactive template in Meteor, where we could let Meteor do the work of changing titles and meta tags.

Note

It is planned to make the head tag a reactive template, but probably not before version 1.0.

To change the document title, we need to come up with a different way of changing it, based on the current route.

Luckily, iron:router has the onAfterAction() function, which can also be used in the Router.configure() function to run before every route. In this function, we have access to the data context of the current route, so we can simply set the title using native JavaScript:

Router.configure({
    layoutTemplate: 'layout',
    notFoundTemplate: 'notFound',

    onAfterAction: function() {
        var data = Posts.findOne({slug: this.params.slug});

        if(_.isObject(data) && !_.isArray(data))
...