Skip to content

Instantly share code, notes, and snippets.

@kayue
Created June 30, 2015 17:41
Show Gist options
  • Save kayue/8e046c2c26552e8f5c1a to your computer and use it in GitHub Desktop.
Save kayue/8e046c2c26552e8f5c1a to your computer and use it in GitHub Desktop.
// Create view
Posts.views.add("latest", function (terms) {
return {
options: {sort: {lastCommentedAt: -1}}
};
});
// Route controller
Posts.controllers.latest = Posts.controllers.list.extend({
view: "latest"
});
// Create route
Router.route('/latest', {
name: 'posts_latest',
controller: Posts.controllers.latest
});
// Override default "/" route
Router.onBeforeAction(function () {
if (Router.current().route.getName()==="posts_default") {
this.render("posts_list_controller", {
data: {
terms: {
view: 'latest', // ideally this should reuse Posts.controllers.latest's data
limit: 10
}
}
});
} else {
this.next();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment