cmather / meteor-handlebars-server

Server side handlebars support for Meteor
80 stars 14 forks source link

Using server-side templates on the client #18

Open SachaG opened 10 years ago

SachaG commented 10 years ago

Is there any way to share the same template between client and server? My use case is Telescope's notifications, where the same content needs to both appear on the site and get sent by email.

Basically, could I do Handlebars.templates['my-template']({name: 'Chris'}); from the client and get some HTML in return?

cmather commented 10 years ago

I have a similar use case and in the next version of EM I just copied the templating package into my project and enabled server side compiling of the templates. Then they're available on client and server. It even works pretty well with iron-layout and iron-dynamic-template. But it's a bit of a pain to do the rendering. You do something like this:

Blaze.toHTML(myView)

So if you're using Iron.Layout you could so something like this:

var layout = new Iron.Layout({template: 'Layout'});
layout.render('MyPageTemplate');
Blaze.toHTML(layout.create());
SachaG commented 10 years ago

Thanks, I'll look into it :)