Compare two strings in freemarker

Viewed 51094

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.

4 Answers

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.

This is neat and worked for me

${("123"=="1234")?string("yees","noo")}
Related