Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

meteor - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...