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-70) Loop Variables Not Resolving when used as marco arguments
Date Fri, 11 Aug 2017 21:37:00 GMT

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

Daniel Dekany edited comment on FREEMARKER-70 at 8/11/17 9:36 PM:
------------------------------------------------------------------

The problem is not with macros, but with interpolations inside strings, which you happen to
use in that macro call. But something like this on the top-level will fail too:

{code}
<#list 1..2 as loopvar>${"${loopvar?index}"}</#list>
{code}

while if you call the macro like this, it will work:

{code}
<@button caption=loopvar?index?string />
{code}

So the bug that will have to be fixed here is that because the string itself is a like a small
template that's parsed separately, it doesn't inherit the loop variable stack from the enclosing
parser.



was (Author: ddekany):
The problem is not with macros, but with interpolations inside strings, which you happen to
use in that macro call. But something like this on the top-level will fail too:

{code}
<#list 1..2 as loopvar>${"${loopvar?index}"}</#list>
{code}

The problem that will have to be fixed here is that the string itself is a like a small template
that's parse separately, and it doesn't inherit the loop variable stack from the enclosing
parser...

> Loop Variables Not Resolving when used as marco arguments
> ---------------------------------------------------------
>
>                 Key: FREEMARKER-70
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-70
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.26-incubating
>            Reporter: Bill Parkinson
>
> When invoking a macro inside of a #list  the loop variable is not in scope to be used
resolving the argument values to the macro call.
> Example
> {code:java}
> <#macro button caption>
> content irrelevant.
> </#macro>
> <#list ["a","b","c"]>
> <#items as loopvar>
> ${loopvar?counter} -- works
> ${loopvar?index} -- works
> <p class="${loopvar?index}"> -- works
> <@button caption="${loopvar?index}" /> -- FAILS
> </#items>
> </#list>
> {code}
> The @button macro call fails with the message:
> The left hand operand of ?index must be a loop variable, but there's no loop variable
in scope with this name: loopvar
> Shouldn't loopvar be in scope for evaluating those macro argument values?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message