freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <>
Subject [jira] [Commented] (FREEMARKER-21) Reference to the object in condition - avoid repeating the same in #if and ${...}
Date Sat, 30 Sep 2017 11:16:03 GMT


Daniel Dekany commented on FREEMARKER-21:

That was another take on this in duplicate FREEMARKER-75. Based on that, my current ideas
is that we need something like {{expression?as(variableName)}}, which crates a nested content
variable (aka. a loop variable). This built-in would silently bypass {{null}}, so that {{<#if
some.long.expression?as(x)??>}} works. 

There's a problem that it's not possible to assign {{null}} to a variable, so this rises the
question of what happens if I have {{<#if true || some.long.expression?as(x)??>}}, i.e.,
we enter the nested content despite {{x}} wasn't assigned to... Well, it's basically the same
issue as with {{#list}}-ing something that contains {{null}} at some places: reading {{x}}
will fall back to the higher scope. Which is horrible, but, well, that can be fixed together
with {{#list}}, as it's the same problem. (It's not even so hard to fix, the problem is, as
always, backward compatibility...)

> Reference to the object in condition - avoid repeating the same in #if and ${...}
> ---------------------------------------------------------------------------------
>                 Key: FREEMARKER-21
>                 URL:
>             Project: Apache Freemarker
>          Issue Type: New Feature
>          Components: engine
>            Reporter: Ondra Žižka
> Repeating stuff is annoying, especially in programming.
> Therefore this is annoying:
> {code}
> <#if someVariable.someMethod.someProperty??>
> <div>${someVariable.someMethod.someProperty}</div>
> </#if>
> {code}
> This would be better:
> {code}
> <#if someVariable.someMethod.someProperty?? as value>
> <div>${value}</div>
> </#if>
> {code}
> Not talking about the fact that it could only be evaluated once.

This message was sent by Atlassian JIRA

View raw message