Meteor JS : How to take data of an object in specific ?

For do this, you can use in html file :

{{#with object}}
{…}
{{/with}}

In your javascript file you need create some helper to take the object :

Template.NameTemplate.helpers({
    'object': function () {
        return Collection.findOne({});
    }
});

Full Example :

eventDetail.html

<template name="EventDetail">
    {{#with event}}
    <div class="category page-container container">
        <div class="panel panel-default" style="text-align: left">
            <div class="panel-heading">
                <h3 class="panel-title">{{this.name}}</h3>
            </div>
            <div class="panel-body">

                <div class="register-form">
                    {{#if isShowDescription}}
                        <div class="form-group col-xs-12">
                            <div class="input-group">
                                Description
                                {{this.description}}
                            </div>
                        </div>
                    {{/if}}
                </div>
            </div>
        </div>
    </div>
    {{/with}}
</template>

eventDetail.js

Template.EventDetail.helpers({
    'event': function () {
        return Events.findOne({}); // Here I take my object
    },
    'isShowDescription':function() {
        if ( this.description != undefined &&  this.description.length > 0 ){
            return true;
        } else {
            return false;
        }
    }
});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s