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

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

问题描述

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

I have a simple fixture.yml file:

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 标签?

How do I escape the ERB tag?

推荐答案

添加第二个 % 到开始标签:

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天全站免登陆