Reputation: 607
I am using free marker and i am returning response from application as string i need to compare the response with static some string . Here is the way of doing.
${users.isValid}
it is returning "true" in but i am not able to compare this variable form my variable.Code i am using is :
<#if ${parameters.isvalid}>
It is valid data
<#else>
It is Invalid data
</#if>
What is possible way to close this issue thanks in advance.
Upvotes: 15
Views: 65967
Reputation: 11
This is neat and worked for me
${("123"=="1234")?string("yees","noo")}
Upvotes: 1
Reputation: 5129
In freemarker template you cannot use interpolations inside if statement.
It's a frequent mistake to use interpolations on places where they needn't/shouldn't/can't be used. Interpolations work only in text sections (e.g. <h1>Hello ${name}!</h1>
) and in string literals (e.g. <#include "/footer/${company}.html">
).
A typical WRONG usage is <#if ${big}>...</#if>
, which will give syntactical error. You should simply write <#if big>...</#if>
. Also, <#if "${big}">...</#if>
is WRONG, since it converts the parameter value to string and the if directive wants a boolean value, so it will cause a runtime error.
Upvotes: 1
Reputation: 1098
//if isvalid is a string variable...
<#if parameters?? && parameters.isvalid?? && parameters.isvalid="true">
blah blah
<#else>
lah lah
</#if>
//if isvalid is a boolean variable...
<#if parameters?? && parameters.isvalid?? && parameters.isvalid=true>
blah blah
<#else>
lah lah
</#if>
Upvotes: 3
Reputation: 607
I have used the following syntax to compare two string values in freemarker.
<#if parameters.isvalid == "true">
Upvotes: 28