如何在 Freemarker 模板中使用 keep_after_last
How to use keep_after_last in Freemarker template
我有以下代码,我只想保留最后一个字符串或文本,例如ABC G56,所以我只想在 space 之后保留 G56,所以我在 freemarker 中使用 keep_after_last。
<td>${value?keep_after_last(" ")}</td>
但我收到错误:
caused by: freemarker.core.parseexception: error on line 57, column 46, in template .ftl found keep_after_last, expecting one of: date, is_directive, parent, js_string, j_string, replace, uncap_first, float, right_pad, is_transform, number, datetime, node_type, split, is_hash, trim, children, has_content, is_sequence, xml, html, ancestors, new, last, byte, double, left_pad, sort, matches, capitalize, contains, eval, lower_case, size, web_safe, is_date, is_string, word_list, seq_last_index_of, node_namespace, string, keys, values, seq_index_of, chunk, sort_by, is_collection, long, starts_with, substring, index_of, default, root, is_boolean, floor, last_index_of, ceiling, if_exists, c, chop_linebreak, is_macro, rtf, upper_case, length, node_name, is_indexable, groups, reverse, cap_first, is_node, int, url, is_hash_ex, xhtml, ends_with, round, is_enumerable, interpret, is_method, namespace, exists, short, seq_contains, time, first, is_number in .ftl
看来您的 FreeMarker 版本太旧了。 ?keep_after_last
是在 2.3.22 中添加的(参见 https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_keep_after_last)。
如果您不确定您使用的是哪个版本,您可以使用${.version}
输出它(参见https://freemarker.apache.org/docs/ref_specvar.html)。
我有以下代码,我只想保留最后一个字符串或文本,例如ABC G56,所以我只想在 space 之后保留 G56,所以我在 freemarker 中使用 keep_after_last。
<td>${value?keep_after_last(" ")}</td>
但我收到错误:
caused by: freemarker.core.parseexception: error on line 57, column 46, in template .ftl found keep_after_last, expecting one of: date, is_directive, parent, js_string, j_string, replace, uncap_first, float, right_pad, is_transform, number, datetime, node_type, split, is_hash, trim, children, has_content, is_sequence, xml, html, ancestors, new, last, byte, double, left_pad, sort, matches, capitalize, contains, eval, lower_case, size, web_safe, is_date, is_string, word_list, seq_last_index_of, node_namespace, string, keys, values, seq_index_of, chunk, sort_by, is_collection, long, starts_with, substring, index_of, default, root, is_boolean, floor, last_index_of, ceiling, if_exists, c, chop_linebreak, is_macro, rtf, upper_case, length, node_name, is_indexable, groups, reverse, cap_first, is_node, int, url, is_hash_ex, xhtml, ends_with, round, is_enumerable, interpret, is_method, namespace, exists, short, seq_contains, time, first, is_number in .ftl
看来您的 FreeMarker 版本太旧了。 ?keep_after_last
是在 2.3.22 中添加的(参见 https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_keep_after_last)。
如果您不确定您使用的是哪个版本,您可以使用${.version}
输出它(参见https://freemarker.apache.org/docs/ref_specvar.html)。