如何在Freemarker中输出$ {expression}而不进行解释? [英] How to output ${expression} in Freemarker without it being interpreted?
问题描述
我正在尝试将Freemarker与jQuery Templates结合使用。
两个框架都使用美元符号/卷曲括号来标识要替换的表达式(或者它们是在freemarker中称为插值),例如 $ {person.name}
。
因此,当我使用该语法定义带有表达式的jQuery模板时,Freemarker会尝试解释它们(并且失败)。
我尝试了各种转义 $ {
序列的组合,以使其通过Freemarker无效- \ $ {
, \ $ \ {
, $ \ {
等)
在美元和花括号之间插入一个自由标记注释(例如 $<#--> {expression}
)确实可行-但我正在寻找一种更简洁,优雅的解决方案。 c> $ {?
这应打印$ {person.name}:
$ {r $ {person.name}}
一种特殊的字符串文字是原始字符串文字。在原始字符串文字中,反斜杠和$ {没有特殊含义,它们被视为纯字符。为了表明字符串文字是原始字符串文字,您必须在开头的引号或撇号前面加上一个r
I'm trying to use Freemarker in conjunction with jQuery Templates.
Both frameworks use dollar sign/curly brackets to identify expressions for substitution (or as they're called in freemarker, "interpolations") , e.g. ${person.name}
.
So when I define a jQuery Template with expressions in that syntax, Freemarker tries to interpret them (and fails).
I've tried various combinations of escaping the ${
sequence to pass it through Freemarker to no avail - \${
, \$\{
, $\{
, etc.
Inserting a freemarker comment in between the dollar and the curly (e.g. $<#-- -->{expression}
) DOES work - but I'm looking for a more concise and elegant solution.
Is there a simpler way to get a Freemarker template to output the character sequence ${
?
This should print ${person.name}:
${r"${person.name}"}
From the freemarker docs
A special kind of string literals is the raw string literals. In raw string literals, backslash and ${ have no special meaning, they are considered as plain characters. To indicate that a string literal is a raw string literal, you have to put an r directly before the opening quotation mark or apostrophe-quote
这篇关于如何在Freemarker中输出$ {expression}而不进行解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!