How to use Meteor methods inside of a template helper

There is now a new way to do this (Meteor 0.9.3.1) which doesn’t pollute the Session namespace Template.helloWorld.helpers({ txt: function () { return Template.instance().myAsyncValue.get(); } }); Template.helloWorld.created = function (){ var self = this; self.myAsyncValue = new ReactiveVar(“Waiting for response from server…”); Meteor.call(‘getAsyncValue’, function (err, asyncValue) { if (err) console.log(err); else self.myAsyncValue.set(asyncValue); }); } In … Read more

Using Multiple Mongodb Databases with Meteor.js

Update It is now possible to connect to remote/multiple databases: var database = new MongoInternals.RemoteCollectionDriver(“<mongo url>”); MyCollection = new Mongo.Collection(“collection_name”, { _driver: database }); Where <mongo_url> is a mongodb url such as mongodb://127.0.0.1:27017/meteor (with the database name) There is one disadvantage with this at the moment: No Oplog Old Answer At the moment this is … Read more

Jade templating in Meteor

We would love to see Jade integration. Use packages/handlebars as a template. The basic strategy is to wire the output of the template engine into Meteor.ui.render which is how we implement live page updates. As long as your template returns HTML, that’ll work. Any time a Jade template references a Meteor.Collection document or Session variable, … Read more

How does the messages-count example in Meteor docs work?

Thanks for prompting me to write a clearer explanation. Here’s a fuller example with my comments. There were a few bugs and inconsistencies that I’ve cleaned up. Next docs release will use this. Meteor.publish is quite flexible. It’s not limited to publishing existing MongoDB collections to the client: we can publish anything we want. Specifically, … Read more

Ordering of the css and js files loaded by Meteor

This question has since been answered in http://docs.meteor.com/ The JavaScript and CSS files in an application are loaded according to these rules: Files in the lib directory at the root of your application are loaded first. Files that match main.* are loaded after everything else. Files in subdirectories are loaded before files in parent directories, … Read more

The context of “this” in Meteor template event handlers (using Handlebars for templating)

This video explains the concepts: http://www.eventedmind.com/posts/meteor-spark-data-annotation-and-data-contexts. The direct answer to your question: The thisArg inside an event handler should point to a data context. But sometimes the data context is undefined. When you use the Function.prototype.call(thisArg, …) in JavaScript, if the thisArg is undefined (e.g. a dataContext is undefined) the browser will set this equal … Read more

How to build a Meteor smart package

Meteor now supports a create –package command. See the meteor docs. Example (substitute your own meteor developer account for “cunneen”): meteor create –package cunneen:foo Output: cunneen:foo: created in your app Results: packages/cunneen:foo/package.js Package.describe({ name: ‘cunneen:foo’, version: ‘0.0.1’, // Brief, one-line summary of the package. summary: ”, // URL to the Git repository containing the source … Read more