Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5E3ED200D0F for ; Fri, 29 Sep 2017 09:30:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5C86B1609ED; Fri, 29 Sep 2017 07:30:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A30CF1609D1 for ; Fri, 29 Sep 2017 09:30:04 +0200 (CEST) Received: (qmail 29673 invoked by uid 500); 29 Sep 2017 07:30:03 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 29663 invoked by uid 99); 29 Sep 2017 07:30:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Sep 2017 07:30:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 30761180D83 for ; Fri, 29 Sep 2017 07:30:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id kZRpunJdladY for ; Fri, 29 Sep 2017 07:30:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 58B7F5FD48 for ; Fri, 29 Sep 2017 07:30:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id C47CBE0C1D for ; Fri, 29 Sep 2017 07:30:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 77370242AF for ; Fri, 29 Sep 2017 07:30:00 +0000 (UTC) Date: Fri, 29 Sep 2017 07:30:00 +0000 (UTC) From: "Daniel Dekany (JIRA)" To: notifications@freemarker.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FREEMARKER-76) New built-in ?if(condition, otherwise) to override left-hand expr. conditionally MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 29 Sep 2017 07:30:05 -0000 [ https://issues.apache.org/jira/browse/FREEMARKER-76?page=3Dcom.atlass= ian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1= 6185453#comment-16185453 ]=20 Daniel Dekany commented on FREEMARKER-76: ----------------------------------------- I assume {{expensiveCall()?as("cached")!false}} really meant to be {{expens= iveCall()!false?as("cached")}}, so the {{?if(cache)}} will work. Anyway, th= e use case seems to be a variation of this pattern: {{code}} <#if someExpensiveExpression??> Print something around ${someExpensiveExpression}. {{code}} which could be addressed as: {{code}} <#if someExpensiveExpression?as(x)??> Print something around ${x}. {{code}} It's longer than your version, but your is very strange because, apparently= , it tries to print something inside a string literal only so that it can u= se the {{?something}} syntax. That's problematic, among others because of h= ow auto-escaping works. There's an issue with my above application of {{?as}} as well though... bec= ause of the fail-fast behavior of FM2 with {{null}}-s, it's quite unusual t= hat {{?as}} can continue even if its left side is {{null}}, and much worse,= in that case all I could implement is returning with {{null}}, and not doi= ng the assignment. Because storing {{null}} in a variable just would make i= t transparent, that is, reading it would cause a fallback to a higher scope= ... (Yip, there are reasons why FM3 was started.) Though in the above issue= it doesn't mater, because if it was {{null}}, then {{??}} will be {{false}= }, and so you don't enter the {{if}} block where {{x}} would be in scope. > New built-in ?if(condition, otherwise) to override left-hand expr. condit= ionally > -------------------------------------------------------------------------= ------- > > Key: FREEMARKER-76 > URL: https://issues.apache.org/jira/browse/FREEMARKER-76 > Project: Apache Freemarker > Issue Type: New Feature > Components: engine > Affects Versions: 2.3.26-incubating > Reporter: Ondra =C5=BDi=C5=BEka > > I propose this built-in: > {code} > expr?if(condition, otherwise) > {code} > This would check condition, and if true, it would pass along the {{expr}} > If condition was false, it would pass along the {{otherwise}}. > The diffrence from {{condition?then(expr, otherwise)}} is that {{expr}} w= ould be evaluated even if {{condition}} was false. The otherwise could be = optional and default to "". > For instance, > {code} > ${ "Hi, ${user}!"?if(user??) } > {code} > The true benefit of {{?if}} would be when used with {{as?}}, proposed in = FREEMARKER-75. =20 > {code} > ${ "Hi, ${expensiveCall()?as("cached")!false}, again!"?if(cached) } > {code} > Without these goodies, this would look like this: > {code} > <#assign cached =3D expensiveCall() > > <#if cached?has_content > > Hi, ${ cached }, again! > > {code} > I hope I didn't overlook some other obvious solution :) -- This message was sent by Atlassian JIRA (v6.4.14#64029)