freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <>
Subject [jira] [Commented] (FREEMARKER-8) Adding to a hash (map)
Date Tue, 10 Nov 2015 19:20:11 GMT


Daniel Dekany commented on FREEMARKER-8:

OK, part of my above answers was hasty...

There is {{++}} in FTL, but it can only be use in assignments. You can't modify the value
of a variable in the middle of a generic expression.

As of the feature request, not everyone will agree that allowing map and list modifications
in a template is a good strategy. You aren't supposed to modify the data model. It can happen
though that such operation would be useful for internal calculations, so that's a valid reason
for it. OTOH we don't want to encourage people to implement complex algorithms in FTL... it's
not a programming language, it's just a template language language.

Also, if you really need to do that, and you know that you have a `Map` behind some variable,
then you can do `myMap?api.put(key, value)` and such (i.e., use the Java API of the object),
after configuring FreeMarker to allow that (see related FAQ entry).

> Adding to a hash (map)
> ----------------------
>                 Key: FREEMARKER-8
>                 URL:
>             Project: Apache Freemarker
>          Issue Type: New Feature
>          Components: engine
>    Affects Versions: 2.3.23
>            Reporter: Ondra Žižka
> It would be nice to assign to a map this way:
> {code}
> <#assign map["key"] = 1>
> {code}
> and also 
> {code}
> <#assign map["key"]++>
> {code}
> So far I think it's like this but can't get it work:
> {code}
> <#assign map += {classification.classification : map[classification.classification]!++}>
> {code}
> Thanks for considering.

This message was sent by Atlassian JIRA

View raw message