freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pedro M. Zamboni (JIRA)" <>
Subject [jira] [Commented] (FREEMARKER-21) Reference to the object in condition - avoid repeating the same in #if and ${...}
Date Mon, 13 Feb 2017 02:03:41 GMT


Pedro M. Zamboni commented on FREEMARKER-21:

Hello, Daniel. Thanks for the quite speedy response!

Sorry, I found Freemarker last year, and only now I’ve been taking a look at it more closely.
I did not know you could not store the missing value in a variable. But wouldn’t this feature
as you describe be equally problematic? Consider:

<#if (foo as bar)!"Hello!" == "Hello!">
	${bar} <#-- outputs what? -->

However, I don’t understand what you mean by “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”. If this currently is impossible, doesn’t it mean the behavior of doing it would
still have to be defined? I don’t understand why it _would_ have to look for it in enclosing
scopes, and couldn’t simply let the variable containing the missing value shadow outer variables.

Either way, I’m writing a suggestion for better missing value (“null”) handling in Freemarker,
and I have a better idea on how to handle that use‐case without allowing {{as}} in arbitrary
expressions. I plan on posting it later today (13 Feb 2017 BRST).

> 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