algorithmicCoder
algorithmicCoder

Reputation: 6789

Return Multiple Values in Meteor for Handlebars Template

How do I do this in Meteor?

Template.foo.bar = function() {


someVar = return value of some other function
return SomeCollection and someVar;

}

-------Template----

{{#each someCollection}}
{{someVar}} {{someCollectionField}}
{{/each}}

in regular javascript I could just use an array to return multiple values how does it work in Meteor?

Upvotes: 1

Views: 1870

Answers (1)

Tarang
Tarang

Reputation: 75945

You could return a js object and use handlebars to go through it

Client js

Template.foo.bar = function() {
    someVar = getmyotherfunction();
    return {
            SomeCollection: SomeCollection.find({...}),
            someVar: someVar
           };

}

Client html

<template name="foo">
    {{#each bar.SomeCollection}}
        {{bar.someVar}} 
        {{someCollectionField}}
    {{/each}}
</template>

You can access a bar value inside the handlebars each loop and just use . to get inside objects. Arrays also work, use .0 to get the first item in the array, 0 being the index.

Upvotes: 3

Related Questions