Reputation: 15107
I am iterating over a list from 0-26, and would like to get the corresponding letter with each. For example, 0 will give me letter 'A' and so on.
I know that in java I can say: char A = (char)65; and that will give me an 'A' from my 65 integer.
But how can i do this on the front-end with freemarker, I have no clue?
Upvotes: 0
Views: 1098
Reputation: 31112
Update: In FreeMarker 2.3.22 you can just use the (i + 1)?upper_abc
expression. (The + 1
is needed if i
is 0-based.)
Unfortunately, FreeMarker has no operator for that, yet. Although it's still possible to achieve this purely in FreeMarker by building a string literal that uses a \x
escape and then ?eval
it, that would be very ugly and inefficient. So the proper solution for now is to write your own TemplateMethodModelEx
, and put it into #import
-et utility library (if you have one) with <#assign numToChar = 'com.example.NumToCharMethod'?new()>
, or add it as shared-variable in the Configuration
.
Upvotes: 1