-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.js
41 lines (35 loc) · 927 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Posts = new Mongo.Collection('posts');
if (Meteor.isClient) {
Template.post.onCreated(function() {
var self = this;
self.autorun(function() {
self.subscribe('post', FlowRouter.getParam('slug'));
});
});
Template.post.helpers({
post: function() {
return Posts.findOne({ slug: FlowRouter.getParam('slug') });
}
});
}
FlowRouter.route('/', {
action: function() {
BlazeLayout.render('layout', { main: 'home' });
}
});
FlowRouter.route('/post/:slug', {
action: function() {
BlazeLayout.render('layout', { main: 'post' });
}
});
if (Meteor.isServer) {
if (Posts.find().count() === 0) {
Posts.insert({ slug: 'post-1', title: 'Post 1' });
Posts.insert({ slug: 'post-2', title: 'Post 2' });
Posts.insert({ slug: 'post-3', title: 'Post 3' });
}
Meteor.publish('post', function(slug) {
check(slug, String);
return Posts.find({ slug: slug });
});
}