freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (FREEMARKER-21) Reference to the object in condition - avoid repeating the same in #if and ${...}
Date Mon, 13 Feb 2017 20:42:41 GMT

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

Daniel Dekany edited comment on FREEMARKER-21 at 2/13/17 8:42 PM:
------------------------------------------------------------------

{{(exp)\!exp}} is special, in that it allows the exception to be raised. {{absent?has_content}}
doesn't raise an exception anywhere, nor {{absent!'Good bye'}}. The way it works is that something
evaluating to "missing" (to Java {{null}} on the lower level) is not an error in itself. The
exception is raised when you try to do something with that missing value ({{null}}), and that
operation, like outputting it, or `#assign` it to something, doesn't allow {{null}}-s. And
almost nothing allows {{null}}-s in FreeMarker 2, but of course things that were specifically
made to deal with missing values (such as {{?has_content}}) do. So this is what we have to
work with in FM2. (I want it to be different in FM3.)


was (Author: ddekany):
`(exp)\!exp` is special, in that it allows the exception to be raised. `absent?has_content`
doesn't raise an exception anywhere, nor `absent!'Good bye'` doesn't either. The way it works
is that something evaluating to "missing" (to Java `null` on the lower level) is not an error
in itself. The exception is raised when you try to do something with that missing value (`null`),
and that operation, like outputting it, or `#assign` it to something, doesn't allow `null`-s.
And almost nothing allows `null`-s in FreeMarker 2, but of course things that were specifically
made to deal with missing values (such as `?has_content`) do. So this is what we have to work
with in FM2. (I want it to be different in FM3.)

> 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)

Mime
View raw message