How do I get Blaze templates to render an HTML string?

1,418 views
Skip to first unread message

Gregg Cooke

unread,
Apr 3, 2014, 10:30:25 AM4/3/14
to meteo...@googlegroups.com
I've found it very useful to have the old Spark engine render a template and pass me back the string of HTML, like so:

var reply = Template.confirmFeedback({
                name: name.split(' ')[0],
                email: addr });

I have a dozen examples of this technique littering my code now, and while there may be better ways to do the same thing, right now this is the one thing that stands in my way of switching over to Meteor 0.8.0 -- because Blaze doesn't seem to have a way to (a) output a rendered template as a string, and (b) forget about the variables that went into rendering the template.

How do I get this done using Blaze templates?  Is there another Handlebars-like template engine I can use?  How do the Meteor team expect people to use the templating engine to render HTML strings in v0.8.0+ (ie, what's the best method intended to be)?

Eric Yen

unread,
Apr 3, 2014, 12:27:35 PM4/3/14
to meteo...@googlegroups.com
Not 100% sure if this what you are looking for since I haven't tried it,
but this looks like what you are looking for:

Gregg Cooke

unread,
Apr 3, 2014, 12:36:33 PM4/3/14
to meteo...@googlegroups.com

Eric -- UI.renderWithData() won't work because what it produces is an object that can only be passed into UI.insert() to add to the DOM tree.  I played around with the idea of trying to add it to an element that's hidden, or to an isolated element, but there's still the issue that I do not want Blaze to treat these template's data reactively.

What I am working on now, and it does seem to work (though it forces me to violate the DRY principle) is the Meteorite package plain-handlebars, which is just the Handlebars library made safe for use within Meteor.  Still, the jury is out: I'm not yet convinced this is the better approach.

--Gregg

April 3, 2014 at 11:27 AM
Not 100% sure if this what you are looking for since I haven't tried it,
but this looks like what you are looking for:
http://docs.meteor.com/#ui_renderwithdata

On Thursday, April 3, 2014 10:30:25 AM UTC-4, Gregg Cooke wrote:
--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
April 3, 2014 at 9:30 AM
I've found it very useful to have the old Spark engine render a template and pass me back the string of HTML, like so:

I have a dozen examples of this technique littering my code now, and while there may be better ways to do the same thing, right now this is the one thing that stands in my way of switching over to Meteor 0.8.0 -- because Blaze doesn't seem to have a way to (a) output a rendered template as a string, and (b) forget about the variables that went into rendering the template.

How do I get this done using Blaze templates?  Is there another Handlebars-like template engine I can use?  How do the Meteor team expect people to use the templating engine to render HTML strings in v0.8.0+ (ie, what's the best method intended to be)?

--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Greenspan

unread,
Apr 3, 2014, 1:15:22 PM4/3/14
to meteo...@googlegroups.com
A few people have asked about this, so I'm putting the answer here: https://github.com/meteor/meteor/issues/2007
Reply all
Reply to author
Forward
0 new messages