从MongoDB中检索HTML以在Template中使用 [英] Retrieving HTML from MongoDB for use in Template

查看:199
本文介绍了从MongoDB中检索HTML以在Template中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Meteor.js和MongoDB的新手,所以这个问题可能有一个明显的解决方案,我失踪了,但到目前为止我的搜索没有任何结果。



我的第一个Meteor项目是一个非常简单的博客。在MongoDB中,我有以下内容:

  Blog.insert({
author:Name here,
title:标题在这里,
headerHTML:这是我的< b>非常< / b>的第一篇博文。,
bodyHTML:是什么促使我们去解决< em> ; / em>这些类型的问题?,
date:new Date()
});

然后在blog.js中有:

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

最后,在我的HTML中,我有以下内容:

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

当我运行由{{headerHTML}}和{{bodyHTML}}指定的部分时,返回文字字符串。所以你可以在文本中看到标签。我想要的是将字符串视为HTML并将其显示。所以一些文本将被加粗,我可以有链接,等等...任何智慧可以抛出我的方式吗?

我试着把把手放在各种HTML标签中(例如< p> {{bodyHML}}< / p> )。解决方案

使用三个括号 {{{}}} 来告诉meteor不要转义您的html字符串。

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


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.

解决方案

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

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

这篇关于从MongoDB中检索HTML以在Template中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆