Crash Override
Crash Override

Reputation: 1427

Meteor Publish Composite is not working with Iron Router

I am trying the reywood:publish-composite package in Meteor, and not have basic success. The Template is not displaying fields pulled from the MongoDB Collection.

/server/publish.js

Meteor.publishComposite("PDetail", function(pShortname) {
  console.log("Browser asked to subscribe to PDetail with: " + pShortname);
  return {
    find: function() {
      return Proj.find( {shortname: pShortname} );
    }
  }
});

/collections/collections.js

Proj = new Mongo.Collection('proj');

/client/app.js

Router.route('proj', {
  path: '/proj/:shortname',
  template: 'proj',
  waitOn: function() {
    return Meteor.subscribe('PDetail', this.params.shortname);
  }
});

/client/proj/proj.html

<template name="proj">
  <h1>Name: {{pname}}</h1>
</template>

All I get is Name: without a pname value.

I confirmed the MongoDB database does have Collection data that matches the shortname query, and the pname does have a value. On the server, I do see a successful "Browser asked to subscribe" console.log message with the shortname passed into it (the console.log shown above).

I thought I followed the publish-composite documentation correctly, but things get a little vague when adding Iron Router to the mix. Any thoughts would be appreciated!

Upvotes: 1

Views: 490

Answers (1)

tarmes
tarmes

Reputation: 15442

Your route function needs to return a data context;

Router.route('proj', {
  path: '/proj/:shortname',
  template: 'proj',
  waitOn: function() {
    return Meteor.subscribe('PDetail', this.params.shortname);
  }
  data: Proj.findOne({shortname: this.params.shortname});
});

Upvotes: 0

Related Questions