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 Mon, 13 Feb 2017 00:16:41 GMT


Daniel Dekany commented on FREEMARKER-21:

Sure, `as` doesn't clash with the `#list` syntax in the technical sense, but it looks too
confusing for humans (and adds some extra challenge for tool authors perhaps).

The variable assignment doesn't work because it's illegal to assign a missing value to a variable.
(Even if you still did it somehow, the variable itself would have a "missing value", so FreeMarker
would fall back to look for in enclosing scopes.)

As of the original feature request, the specific use case shown is probably typical enough
in templates to deserve some terser solution. What's the best solution for it is a question

> 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