Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving HTML from MongoDB for use in Template

I'm new to Meteor.js and MongoDB so this question might have an obvious solution that I am missing but so far my searches have turned up nothing.

My first Meteor project is a very bare-bones blog. In the MongoDB I have the following:

    Blog.insert({
      author: "Name Here",
      title: "Title Here",
      headerHTML: "This is my <b>very</b> first blog post.",
      bodyHTML: "What drives us to <em>solve</em> these types of problems?",
      date: new Date()
    });

Then in blog.js I have:

    if (Meteor.isClient) {
        Meteor.subscribe("blog");
        Template.posts.entry = function () {
          return Blog.find({});
        };
    }

And finally in my HTML I have the following

    ...
    <div class="row">
        {{> posts}}
    </div>
    ...
    <template name="posts">
      <div class="span12">
      {{#each entry}}
        {{author}}
        {{date}}
        {{title}}
        {{headerHTML}}
        {{bodyHTML}}
      {{/each}}
      </div>
    </template>

When I have the app running the sections specified by {{headerHTML}} and {{bodyHTML}} return the literal string. So you see the tags in the text. What I want is for the string to be treated as HTML and displayed as such. So some text will be bolded, I could have links, etc... Any wisdom someone can throw my way?

I've tried putting the handlebars in various HTML tags (like <p>{{bodyHML}}</p>) with no luck.

like image 439
1000Cranes Avatar asked May 15 '13 12:05

1000Cranes


People also ask

Can I use MongoDB with HTML and CSS?

MongoDB NodeJS Driver APIs are used for the database server programming to read, add and delete data. The Web Server and the routes are defined using the ExpressJS web app framework. The browser client is built using HTML, CSS and Plain (Old) JavaScript.

How retrieve data from MongoDB?

You can use read operations to retrieve data from your MongoDB database. There are multiple types of read operations that access the data in different ways. If you want to request results based on a set of criteria from the existing set of data, you can use a find operation such as the find() or findOne() methods.


1 Answers

Use three brackets {{{ }}} to tell meteor not to escape your html strings.

 {{{headerHTML}}}
 {{{bodyHTML}}}
like image 159
Tarang Avatar answered Sep 28 '22 05:09

Tarang