Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

I have a Freemarker template which contains a bunch of placeholders for which values are supplied when the template is processed. I want to conditionally include part of the template if the userName variable is supplied, something like:

[#if_exists userName]

  Hi ${userName}, How are you?

[/#if_exists]

However, the FreeMarker manual seems to indicate that if_exists is deprecated, but I can't find another way to achieve this. Of course, I could simple providing an additional boolean variable isUserName and use that like this:

[#if isUserName]

  Hi ${userName}, How are you?

[/#if]

But if there's a way of checking whether userName exists then I can avoid adding this extra variable.

1 Answer

0 votes
by (46k points)

This one seems to be a better fit:

<#if userName?has_content>

... do something

</#if>

http://freemarker.sourceforge.net/docs/ref_builtins_expert.html

Related questions

0 votes
1 answer
asked Oct 9, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Oct 29, 2019 in Java by Anvi (10.2k points)
0 votes
2 answers
0 votes
1 answer
asked Jul 9, 2019 in Java by prachi95 (1.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...