Expand a boolean variable to the string "true" or "false"

tangens picture tangens · Oct 2, 2009 · Viewed 26.3k times · Source

In a freemarker template I want to expand a boolean variable to a string like that:

<#assign booleanVar = "test".isEmpty() />
state: ${booleanVar} <#-- this throws an exception! -->

This is what I want to get as output:

state: false

The only way I found to reach this goal by now is:

state: <#if booleanVar>true<#else>false</#if>

Is there a easier way to do it?

Answer

tsilb picture tsilb · Oct 2, 2009
booleanVar?string("true", "false")

Although true/false is default, so

booleanVar?string

should work fine.