Reputation: 11122
To iterate over hashmaps one can use the hash built-in to access values and keys of a Map. Now I want to operate on the key, i.e. to upperCase the key (which is a string):
<#assign keys = formats?keys>
<#list keys as key>
${key.toUpperCase()} = ${formats[key].getFileName()}
</#list>
But I get the error
For "." left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
==> key [in template "src/main/resources/test.ftl" at line 41, column 69]
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${key.toString().toUpperCase()} [in template "src/main/resources/test.ftl" at line 41, column 67]
----
Any hint how to get the key (which is lowercase) to upper case in the template? or how to convert the hash to a String?
Upvotes: 1
Views: 10951
Reputation: 31112
In FreeMarker the Java API of many basic classes (such as String
, Number
, List
, etc.) is hidden. Instead of their API-s, you are supposed to use so called "built-ins", like in this case: key?upper_case
. (See also: http://freemarker.org/docs/ref_builtins.html)
Upvotes: 2