Handlebars java - 助手中的引号
Handlebars java - quotes in helper
我正在使用 jknack handlebars.java v4.2.0
我想在我的模板中包含一个字段(如果该字段不为空)并且我希望该字段用双引号引起来。
例如
You have received a payment. "Food expenses"
或者如果没有提供参考:
You have received a payment.
我试着为此写了一个自定义助手:
@SneakyThrows
public CharSequence formattedPaymentReference(String paymentReference) {
return isEmpty(paymentReference) ? Strings.EMPTY : String.format("\"%s\"", paymentReference);
}
然后更新我的模板:
You have received a payment. {{formattedPaymentReference reference}}
但是输出不是我需要的,它没有使用实际的引号。
You have received a payment. "Food expenses"
有更好的方法吗?
谢谢
@SneakyThrows
public CharSequence formattedPaymentReference(String paymentReference) {
return isEmpty(paymentReference) ? Strings.EMPTY : new SafeString(String.format("\"%s\"", paymentReference));
}
使用 Handlebars.SafeString 对引号进行转义。
我正在使用 jknack handlebars.java v4.2.0
我想在我的模板中包含一个字段(如果该字段不为空)并且我希望该字段用双引号引起来。
例如
You have received a payment. "Food expenses"
或者如果没有提供参考:
You have received a payment.
我试着为此写了一个自定义助手:
@SneakyThrows
public CharSequence formattedPaymentReference(String paymentReference) {
return isEmpty(paymentReference) ? Strings.EMPTY : String.format("\"%s\"", paymentReference);
}
然后更新我的模板:
You have received a payment. {{formattedPaymentReference reference}}
但是输出不是我需要的,它没有使用实际的引号。
You have received a payment. "Food expenses"
有更好的方法吗?
谢谢
@SneakyThrows
public CharSequence formattedPaymentReference(String paymentReference) {
return isEmpty(paymentReference) ? Strings.EMPTY : new SafeString(String.format("\"%s\"", paymentReference));
}
使用 Handlebars.SafeString 对引号进行转义。