Retrieving HTML from MongoDB for use in Template

倖福魔咒の 提交于 2019-11-26 21:50:10

问题


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.


回答1:


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

 {{{headerHTML}}}
 {{{bodyHTML}}}


来源:https://stackoverflow.com/questions/16565054/retrieving-html-from-mongodb-for-use-in-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!