Meteor (how to publish search without autopublish)

Hi, anyone please help me. I have created code search for my project. I have problem to publish the result without autopublish. This my code in html and javascript.

Carian

Maklumat

    {{#each profil}}
  1. {{jenama}}
  2. {{/each}}
//js Template.search.events({ "submit #searchform": function (e) { e.preventDefault(); Session.set("kategori", e.target.text.value); } });

Template.search.helpers({
profil: function() {
return Profil.find({
kategori: Session.get(‘kategori’),
});
}
});

We can’t read your code. Please wrap your code and html snippets in triple backticks like this:

```
your code/html here
```

This my code html
`

Carian

Maklumat

    {{#each profil}}
  1. {{jenama}}
  2. {{/each}}
````

//js
Template.search.events({
“submit #searchform”: function (e) {
e.preventDefault();
Session.set(“kategori”, e.target.text.value);
}
});
Template.search.helpers({
profil: function() {
return Profil.find({
kategori: Session.get(‘kategori’),
});
}
});

Do you have a publication or subscription set up?

No. That it I dont know how to code.

Creating a publication based on a search is a bit more complicated, I’d say start with a normal publication with searchable subscription data:

server.js:

Meteor.publish('profil', function () {
  console.log('Profil Count:', Profil.find().count());
  return Profil.find();
});

client.js:

Template.search.onCreated(function () {
  var self = this;
  self.autorun(function () {
    var profilSub = self.subscribe('profil');
    if (profilSub.ready()) {
      console.log('subscribed');
    }
  });
});

Once you get that working, post back here and we can check out adding a search to the pub/sub?

This code not working to my project.

How about iron router? how declare searching in iron router?

Well, you need your publications and subscriptions working first. Then you can add searching to your publication. Do you have any errors when using the code I posted?

No any error and no any output.

Can you try the edited version of the code above – check your server log as well.