我正在尝试用Haml + Mustache创建一个博客,但是字段'description‘有一个CKEditor,因此该字段总是包含html标签,但是Mustache不会呈现为html,即使放入’description ption.html_safe‘。
我的助手:
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初始化器:
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)发布于 2012-08-03 02:51:39
我猜你在你的胡子里做了一些类似的事情:
{{description}}如果description包含超文本标记语言,你需要说:
{{{description}}}从fine manual
变量
..。
默认情况下,所有变量都是HTML转义的。如果你想返回未转义的超文本标记语言,使用三重胡子:{{{name}}}.
因此,{{description}}将由Mustache编码,但{{{descriptipn}}}将按原样使用description。
https://stackoverflow.com/questions/11783409
复制相似问题