首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Haml + Mustache

Haml + Mustache
EN

Stack Overflow用户
提问于 2012-08-03 02:16:14
回答 1查看 1.1K关注 0票数 1

我正在尝试用Haml + Mustache创建一个博客,但是字段'description‘有一个CKEditor,因此该字段总是包含html标签,但是Mustache不会呈现为html,即使放入’description ption.html_safe‘。

我的助手:

代码语言:javascript
复制
def post_for_mustache(post)
{
  post: {
    category: {
      url: category_order_path(:category => post.category.to_param),
      name: post.category.name
    },
    url: category_post_path(:category => post.category.to_param,
                            :slug => post.to_param),
    title: post.title,
    comment_enabled: post.comment_enabled,
    description: post.description.html_safe,
    title_escape: URI.escape(post.title),
    url_escape: URI.escape(category_post_url(:category => post.category.to_param,
                                             :slug => post.to_param)),
  }
}
end

我的Mustache初始化器:

代码语言:javascript
复制
module MustacheTemplateHandler
  def self.call(template)
    haml = "Haml::Engine.new(#{template.source.inspect}).render"
    if template.locals.include? 'mustache'
      "Mustache.render(#{haml}, mustache).html_safe"
    else
      haml.html_safe
    end
  end
end
ActionView::Template.register_template_handler(:mustache, MustacheTemplateHandler)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-03 02:51:39

我猜你在你的胡子里做了一些类似的事情:

代码语言:javascript
复制
{{description}}

如果description包含超文本标记语言,你需要说:

代码语言:javascript
复制
{{{description}}}

fine manual

变量

..。

默认情况下,所有变量都是HTML转义的。如果你想返回未转义的超文本标记语言,使用三重胡子:{{{name}}}.

因此,{{description}}将由Mustache编码,但{{{descriptipn}}}将按原样使用description

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11783409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档