Created
March 3, 2015 00:42
-
-
Save patrickml/6fd91d266a3d64f793be to your computer and use it in GitHub Desktop.
Meteor Joins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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