mongodb - 从 MongoDB 中检索 HTML 以在模板中使用

标签 mongodb meteor handlebars.js

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

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

    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()
    });

然后在 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 并显示为这样。所以有些文字会加粗,我可以有链接,等等......有人可以告诉我任何智慧吗?

我尝试将 Handlebars 放在各种 HTML 标记中(如 <p>{{bodyHML}}</p>),但没有成功。

最佳答案

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

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

关于mongodb - 从 MongoDB 中检索 HTML 以在模板中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565054/

相关文章:

java - 如何仅从主数据库执行读取操作

javascript - 铁路由器中的多个 waitOn 不起作用

meteor - 停止对一个变量的 react

mongodb条件查询主键_id?

mongodb - 完全外部加入 MongoDB

node.js - Mongoose 复杂(异步)虚拟

javascript - Meteor JS 全局函数

javascript - 客户端 Handlebars 导致 404 请求

javascript - Handlebars - 通过嵌套的 each 中的外部键访问数组

ember.js - 如何为 Ember.js 输入助手设置两个类名