Skip to content

Instantly share code, notes, and snippets.

@patrickml
Created March 3, 2015 00:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patrickml/6fd91d266a3d64f793be to your computer and use it in GitHub Desktop.
Save patrickml/6fd91d266a3d64f793be to your computer and use it in GitHub Desktop.
Meteor Joins
<template name="journal">
<div class="nav-block"></div>
<nav class="journal-nav">
<ul>
<li>
<a href="#" data-type="Design">Design</a>
</li>
<li>
<a href="#" data-type="Development">Development</a>
</li>
<li>
<a href="#" data-type="Case Study">Case Studies</a>
</li>
<li>
<a href="#" data-type="all">All</a>
</li>
</ul>
</nav>
<section class="journal">
{{#each journals}}
<article>
<time pubdate datetime="{{formatDate postedon 'long'}}" title="{{formatDate postedon 'post'}}">{{formatDate postedon "post"}}</time>
<a href="{{pathFor 'journalPost' slug=this.slug}}">
<p class="title">
{{title}}
</p>
</a>
<p class="content">
{{description}}
</p>
<a href="{{pathFor 'journalPost' slug=this.slug}}">
<img src="/assets/journal/arrow.svg" class="img-responsive arrow" alt="Image">
</a>
<address class="author">
<!-- Using the Join -->
<!-- Join the Journals information with the Author who wrote it -->
<img src="{{joinWithAuthor.profile.image}}" />
posted by
<a rel="author" href="#">{{joinWithAuthor.profile.full_name}}</a>
</address>
</article>
{{/each}}
</section>
</template>
Template.journal.journals = function () {
return Session.get('journal_category');
}
Template.journal.helpers({
// Creates the Join
'joinWithAuthor': function() {
var post = this;
var author = Meteor.users.findOne(this.author_id);
return _.extend(post, _.omit(author, '_id'));//Where the magic happens I have no idea and i take no credit for this
}
});
Template.journal.events({
'click .journal-nav a' : function(event, template) {
var _this = $(event.target);
var type = _this.data('type');
var filter = {};
if(type != 'all')
filter = {category: type};
Session.set('journal_category', Journals.find(filter, { sort: { postedon: -1 } }).fetch());
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment