I know that with the help of the template you can display several documents with your attributes, for example:
<template name="hello">
{{
{{message}}
{{/each}}
</template>
Template.hello.greetings = function() {
return Greetings.find();
}
What Greeting.message shows for each welcome document found.
My question is how to use this template for only one document? (including accessible document)
From the javascript side, I would use something like return Greetings.findOne({'id' : Session.get("greeting_id")});
But when using the template:
<template name="hello">
{{message}}
</template>
an error is issued: Uncaught TypeError: Unable to read property message 'undefined
UPDATE
I am currently using this on the JS side using the template suggested by @ tom-wijsman below:
Template.hello.greeting = function() {
var greeting = Greetings.findOne({'id' : Session.get("greeting_id")})
if (greeting)
return greeting;
return {message: ""};
}
source
share