[ 
https://issues.apache.org/jira/browse/FREEMARKER-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15863110#comment-15863110
 ] 

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:

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

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: https://issues.apache.org/jira/browse/FREEMARKER-21
>             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
(v6.3.15#6346)

Reply via email to