Sandeep Nair
Sandeep Nair

Reputation: 3650

Freemarker alternative[syntax] if condition with number

I am using alternative freemarker syntax(the one with square brackets). It works fine but I am not able to figure out how to use if condition to check if a number is greater than or less than. Following is the syntax I have

[#if ${numberCoupons} <= 1]
    [#assign couponsText = 'coupon']
[/#if]

Here "<" symbol fails. Do you know what am I doing wrong here.

Also is there any documentation for list of entire directives that can be used with alternative syntax of freemarker?

Upvotes: 4

Views: 9739

Answers (2)

jamie young
jamie young

Reputation: 1867

You should be able to use any of the following:

[#if (numberCoupons <= 1)]
[#if numberCoupons &lt;= 1]
[#if numberCoupons lte 1]
[#if numberCoupons \lte 1]

I would use the parens.

This is detailed at: http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_comparison

Scroll down just a little to the last paragraph in that section that starts with "There is a little problem"

Upvotes: 6

ddekany
ddekany

Reputation: 31112

In this case the error message should complain about the {, not the <. Are you looking at the good place? Anyway, you can't use ${...} there. It should be simply [#if numberCoupons <= 1].

Upvotes: 0

Related Questions