HAML - >主干模板,转义HTML参数 [英] HAML -> Backbone Template, Unescaping HTML Parameters

查看:214
本文介绍了HAML - >主干模板,转义HTML参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HAML生成一个应用Backbone.js的模板。我需要能够插入<%=布拉赫%GT; 作为HTML属性一拉:

I'm using HAML to generate templates for a Backbone.js app. I need to be able to insert <%= blah %> as an html attribute a la:

%a{:href => "myresources/<% id %>"} My Resource

和有它的输出

<a href='myresources/<%= id %>' >My Resource</a>

在HTML模板。不幸的是,HAML脱HTML参数留下我与

in the html template. Unfortunately, HAML escapes the html parameters leaving me with

<a href='#myresources/&lt;%= id %&gt;'>My Resource</a>

按照 HAML参考的!操作者可用于转义字符串,但不是HTML属性内

According to the HAML Reference the '!' operator can be used for unescaping strings, but not within the HTML attributes.

另外,我会用纯文本呈现锚标记,但由于定位标记是这个特定视图的根,我失去了所有的使用HAML的好处。

Also, I'd use plaintext to render the anchor tag, but since the anchor tag is the root for this particular view, I lose all of the benefits of using HAML.

任何帮助吗?

更新
我没有提到,但我使用LiveReload真正看我的文件系统和运行HAML编译器,并有在LiveReload禁用HTML转义标签属性的设置。 &LT;头一巴掌>如果别人运行到这个问题LiveReload之外,还可以在设置:escape_attrs 选项配置HAML设置时,假

Update I didn't mention, but I'm using LiveReload to actually watch my file system and run the haml compiler, and there was a setting in LiveReload to disable HTML escapes in tag attributes. < head slap > If anyone else runs into this issue outside of LiveReload, you can also set the :escape_attrs option to false when configuring your HAML setup.

推荐答案

您可以配置HAML到无法逃脱使用您的HAML配置中的 escape_attrs 选项标记属性。请参见 HAML选项

You can configure HAML to not escape tag attributes using the escape_attrs option in your HAML configuration. See HAML Options.

这篇关于HAML - &GT;主干模板,转义HTML参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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