Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render HTML of Meteor Session variable?

Tags:

html

meteor

Further to my previous post about obtaining data from objects on the server using Meteor.call I'd like to know how this same data can render HTML once similar object data from the server is received. Here is a simple example:

/server/svr.js
Meteor.methods({
  test: function(text) {
    var result = {};
    result.foo = "<em>" + text + "</em>";
    result.bar = text;
    return result;
  }
});

/client/del.js
Meteor.call('test', "Hello World - May 2012", function(err, data) {
if (err)
  console.log(err);

  Session.set('q', data);
});

Template.hello.greeting = function() {
  return Session.get('q').foo;
};

When I run this code in the standard meteor app I see on the browser window:

Hello World!
<em>Hello World - May 2012</em>

Ideally I'd like the session variable containing the html code to have rendered that which was passed into it (in the simple example above - making the second line italicised when output to the browser). How do I go about accomplishing this?

Thanks in advance for any help!

like image 533
rs77 Avatar asked May 21 '12 21:05

rs77


1 Answers

Use {{{greeting}}} instead of {{greeting}} to make sure it isn't escaped.

like image 178
Tamara Wijsman Avatar answered Oct 18 '22 23:10

Tamara Wijsman