leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
649 stars 159 forks source link

How do I output a template? #137

Closed gregblass closed 8 years ago

gregblass commented 8 years ago

Forgive me but I just don't understand something really basic here. If I'm in a view, and I want to just output a handlebars template, the documentation states:

"You can then invoke the resulting template in your application's JavaScript HandlebarsTemplates'contacts/new';

So I'm trying this in my view:

<script>HandlebarsTemplates['notification'];</script>

But that is just outputting that as text in the browser and not my actual template.

Also what is context?

Just trying to output the content of my template file when rendering the page for the first time.

AlexRiedler commented 8 years ago

FROM Handlebars docs:

var context = {title: "My New Post", body: "This is my first post!"};
var html    = template(context);

HandlebarsTemplates['notification'] is like template above, so

HandlebarsTemplates['notification']({ title: "My New Post" });

gregblass commented 8 years ago

Got it working. Thanks!

Just wondering, I see a lot of activity here about rendering handlebars templates on the server. Is this merged into master and possible at the moment?