Search code examples
javascriptnode.jsmeteoriron-router

Populating a text box with parameter in meteor iron router


So I have a meteor route set up like so:

Router.route('/joinRoom/:_id', function () {   
       this.render('joinRoom');
});

and a simple html template:

<template name="joinRoom">
   <p>Enter Your Room ID</p>
   <input placeholder="1" type="text" class="joinID">
   <button class="submit" type="submit" value="submit">Join Room -></button>
</template>

And I want to populate the data passed in as the _id parameter to be the text inside the <input>.

I tried looking over Iron Router's documentation, but I couldn't figure it out. How do I do this?


Solution

  • You can use Router.current().params in your helpers to get the parameters from the url.

    <input placeholder="1" type="text" class="joinID" value={getId}>
    

    Helper:

    getId: function () {
      var params =  Router.current().params;
      return params && params._id ? params._id : '';
    }