Nesting "if statement" and "foreach statement"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Nesting "if statement" and "foreach statement"

ken4ward
The value in doc.db.persons.personname[0] is thomas.
<#global y = doc.db.persons.personname[0]>

[#foreach item in doc.db.persons]
<#if y != "thomas">
        yes, it is ok
        <#else>
        no, remove it
</#if>
[/#foreach]

Check the code snippet above, it's definite that something is wrong with it, kindly help me fix it. The problem is that the Freemarker interpreter does not interpret the foreach statement, only the if statement it interprets. When compiled it gives an output thus:

Output
[#foreach item in doc.db.persons]
        yes, it is ok
[/#foreach]

So my question is what better way can I write this code for both statements to be interpreted? Hoping to have your take on this. Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nesting "if statement" and "foreach statement"

Daniel Dekany
Wednesday, July 16, 2014, 10:44:45 AM, ken4ward wrote:

> The value in doc.db.persons.personname[0] is thomas.
> <#global y = doc.db.persons.personname[0]>
>
> [#foreach item in doc.db.persons]
> <#if y != "thomas">
>         yes, it is ok
>         <#else>
>         no, remove it
> </#if>
> [/#foreach]
>
> Check the code snippet above, it's definite that something is wrong with it,
> kindly help me fix it. The problem is that the Freemarker interpreter does
> not interpret the foreach statement, only the if statement it interprets.
> When compiled it gives an output thus:
>
> Output
> [#foreach item in doc.db.persons]
>         yes, it is ok
> [/#foreach]
>
> So my question is what better way can I write this code for both statements
> to be interpreted? Hoping to have your take on this.

The problem is that you are mixing [#...] and <#...> syntax. You can
only use one of them in the same template. Furthermore, if you chose
[#...], you have to start the template with [#ftl], unless you
configure FreeMarker to use automatic tag syntax detection (which is
not on by default for backward compatibility).

> Thanks.

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Loading...