Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rendering MongoDB documents with Meteor
<head>
<title>Stackoverflow</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<ul>
{{#each projects}}
<li>
<p>Name: {{name}}</p>
<p>Personnel:
{{#print personnel}}
<li>Name : {{name}}</li>
<li>Rank : {{rank}}</li>
{{/print}}
</p>
</li>
{{/each}}
</ul>
</template>
Projects = new Meteor.Collection("projects");
Personel = new Meteor.Collection("personel");
if (Meteor.is_client) {
/** Create a helper that will iterate over each id in the object **/
Handlebars.registerHelper('print', function(context, options) {
var ret = "<ul>";
for(var i=0, j=context.length; i<j; i++) {
var pers = Personel.findOne({_id:context[i]});
if(pers){
ret = ret + options.fn(pers);//Pass the retrieved personel object to the handlerbars function
}
}
ret += "</ul>"
return ret;
});
Template.hello.projects = function(){
return Projects.find({});
}
/**Dummy**/
var one = Personel.insert({name:"Lander",rank:"CEO"});
var two = Personel.insert({name:"Sander",rank:"CEO"});
var three = Personel.insert({name:"Tree",rank:"CEO"});
Projects.insert({name:"Project 1",personnel:[one,two]});
}
if (Meteor.is_server) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.