Discussion:
[FreeMarker-user] Nesting "if statement" and "foreach statement"
ken4ward
2014-07-16 08:44:45 UTC
Permalink
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.



--
View this message in context: http://freemarker.624813.n4.nabble.com/Nesting-if-statement-and-foreach-statement-tp4655207.html
Sent from the freemarker-user mailing list archive at Nabble.com.
Daniel Dekany
2014-07-16 22:13:19 UTC
Permalink
Post by 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.
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).
Post by ken4ward
Thanks.
--
Thanks,
Daniel Dekany
Loading...