如何在ERB中转义ERB标签 [英] How do I escape the ERB tag in ERB

查看:97
本文介绍了如何在ERB中转义ERB标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的fixture.yml文件:

label:
    body: "<%= variable %>"

问题在于,ERB代码在加载固定装置时被解析,而我实际上希望将主体按字面意思是<%=变量%>"(未插值).

The issue is that the ERB code is parsed as part of loading the fixture, whereas I actually want the body to be literally "<%= variable %>" (un-interpolated).

如何逃脱ERB标签?

推荐答案

在开始标记中添加第二个%:

Add a second % to the opening tag:

label:
    body: "<%%= variable %>"

<%%序列为有效的ERB ,呈现为文字<%.

The <%% sequence is valid ERB, rendered as a literal <%.

这篇关于如何在ERB中转义ERB标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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