meteormeteoritebootbox

How can I use meteor templates with Bootbox?


How can one use Meteor Templates w/ the bootboxjs library?

ie, I have the following template

test.html:

<template name="test">
  <input type="text" name="testtext"/>
</template>

it has some events,

test.js:

Template.test.events({
'keyup input[name="testtext"]' : function () { console.log('key up in testtext'); }
});

How can you use the template to generate a bootbox modal w/ the events?


Solution

    1. Add bootbox to your app (via meteorite): mrt add bootboxjs
    2. You can pass a DOM fragment to bootbox's dialog function. You can get a DOM fragment from Spark.render(...)

    Example:

    bootbox.dialog(
      Spark.render(Template.test),
        [{
          "label" : "Ok",
          "class" : "btn-primary",
           "callback": function() {}
        },{
          "label" : "Cancel",
          "class" : "btn",
          "callback": function() {}
        }],
        {
          "header":"Some Dialog box",
          "headerCloseButton":true,
          "onEscape": function() {}
        }
    );
    

    Bonus Example-- Rendering the html, but without any events:

    bootbox.dialog(
      Template.test({contextVar:'SomeValue'}), // Set your context values here
        [{
          "label" : "Ok",
          "class" : "btn-primary",
           "callback": function() {}
        },{
          "label" : "Cancel",
          "class" : "btn",
          "callback": function() {}
        }],
        {
          "header":"Some Dialog box",
          "headerCloseButton":true,
          "onEscape": function() {}
        }
    );