Rendering HTML using Views, Blaze.render and Blaze.renderWithData


Hi all,

As I am learning how to use Blaze API, I am trying to create programmaticaly a View and render it to the DOM using Blaze.render. The return function of the view should return an html content.

However by doing so the htm is interpreted as text and whatever I tried I just could not succeed in doing so.

Is there a way to achieve this without using pre-defined templates ?

The code :

Template.myTemplate.onRendered(function () {
    var id = document.getElementById("TestView");
    var testView = Blaze.With(
        function () {
            return {
                foo: Session.get('foo')
        function () {
            var data = Blaze.getData();
            var html = "<div>foo value is " + + "</div>"
            return html;
    Blaze.render(testView, id);

The result is upadting reactively with Session.get(‘foo’); but I get the following in the web page :

<div>foo value is testfoo</div>

Instead of:

foo value is testfoo

Anybody knows if this is possible ?

Thanks in advance for your help !


Hi, did you try this:

There is a .safestring function and a triple brackets format for a helper to process HTML



Thanks a lot for your reply and sorry for the delay.

We could not succeed using this approach so we used another way. I will let you know if I try again this and find something.

Thanks again !


Hi! Trying to do something similar, what did you end up using?


Hi, we stopped looking for a solution, and changed completely what we wanted to do so sadly I don’t have any solution for you…

Hope you’ll find what you need.

Best regards,



You can use just this piece of code

Blaze.render(Template.yourTemplateName, document.getElementById(‘yourIdWhereyouWouldLikeToRender’))

Here you can find docs for render function:

See this for full example: