检查地图是否包含 Freemarker 模板中的值
checking if a map contains a value in Freemarker Template
我正在尝试检查地图是否包含有条件地执行某些 freemarker 代码的值。这是我到目前为止得到的:
<#if productLayout.layoutWidgetConfiguration[pos.id]??>
<#assign configId>${productLayout.layoutWidgetConfiguration[pos.id]}</#assign>
<#else>
<#assign configId></#assign>
</#if>
但是我得到这个错误,它基本上不满足 if 条件。
Error executing FreeMarker template freemarker.core.UnexpectedTypeException: For "...[...]" left-hand operand: Expected a sequence or string (or something that's implicitly convertible to string), but this evaluated to an extended_hash (wrapper: f.t.SimpleHash):
==> productLayout.layoutWidgetConfiguration [in template "admin/pages/catalog/products/partials/productLayoutEditorRefreshZone.ftl" at line 7, column 22]
The failing instruction (print stack trace for 9 more):
==> #if productLayout.layoutWidgetConfigu... [in template "admin/pages/catalog/products/partials/productLayoutEditorRefreshZone.ftl" at line 7, column 17]
at freemarker.core.DynamicKeyName.dealWithNumericalKey(DynamicKeyName.java:141) ~[DynamicKeyName.class:2.3.20]
如何检查 freemarker 模板中的地图中是否存在值?
在此处更新:
如果我将其更改为此,哈希似乎不喜欢长键值,如果检查有效,但即使存在该值也不会检索 - 所以我想现在的问题是如何使用 java.lang.Long
键从散列中检索值?
<#assign configId = "">
<#if productLayout.layoutWidgetConfiguration[pos.id?string]?has_content>
Hello
<#assign configId = productLayout.layoutWidgetConfiguration[pos.id?string]>
</#if>
<h1>${pos.id}</h1>
[]
只支持字符串哈希(Map
等)键和数字序列(List
、数组等)索引。目前解决方案不使用 []
for Map
-s with non-String keys。您可以使用对象的 Java API 代替,例如 myMap?api.get(nonStringKey)
等。注意配置中必须允许 ?api
;有关更多信息,请参阅 http://freemarker.org/docs/ref_builtins_expert.html#ref_buitin_api_and_has_api。
我正在尝试检查地图是否包含有条件地执行某些 freemarker 代码的值。这是我到目前为止得到的:
<#if productLayout.layoutWidgetConfiguration[pos.id]??>
<#assign configId>${productLayout.layoutWidgetConfiguration[pos.id]}</#assign>
<#else>
<#assign configId></#assign>
</#if>
但是我得到这个错误,它基本上不满足 if 条件。
Error executing FreeMarker template freemarker.core.UnexpectedTypeException: For "...[...]" left-hand operand: Expected a sequence or string (or something that's implicitly convertible to string), but this evaluated to an extended_hash (wrapper: f.t.SimpleHash):
==> productLayout.layoutWidgetConfiguration [in template "admin/pages/catalog/products/partials/productLayoutEditorRefreshZone.ftl" at line 7, column 22]
The failing instruction (print stack trace for 9 more):
==> #if productLayout.layoutWidgetConfigu... [in template "admin/pages/catalog/products/partials/productLayoutEditorRefreshZone.ftl" at line 7, column 17]
at freemarker.core.DynamicKeyName.dealWithNumericalKey(DynamicKeyName.java:141) ~[DynamicKeyName.class:2.3.20]
如何检查 freemarker 模板中的地图中是否存在值?
在此处更新:
如果我将其更改为此,哈希似乎不喜欢长键值,如果检查有效,但即使存在该值也不会检索 - 所以我想现在的问题是如何使用 java.lang.Long
键从散列中检索值?
<#assign configId = "">
<#if productLayout.layoutWidgetConfiguration[pos.id?string]?has_content>
Hello
<#assign configId = productLayout.layoutWidgetConfiguration[pos.id?string]>
</#if>
<h1>${pos.id}</h1>
[]
只支持字符串哈希(Map
等)键和数字序列(List
、数组等)索引。目前解决方案不使用 []
for Map
-s with non-String keys。您可以使用对象的 Java API 代替,例如 myMap?api.get(nonStringKey)
等。注意配置中必须允许 ?api
;有关更多信息,请参阅 http://freemarker.org/docs/ref_builtins_expert.html#ref_buitin_api_and_has_api。