Skip to main content
Participating Frequently
Apr 4, 2022 12:54 PM UTC
Question

Handling condition in freemarker docx template

We have two fields drillTime and drillDateTime.

Condition:

If there is a value in drillTime print drillTime or if it is null

Print drillDateTime

[#if dmd.drillTime??]
${dmd.drillTime!""}
[#elseif dmd.drillDateTime??]
${dmd.drillDateTime??}

Above we used in template but its not working correctly.

Its printing drillTime if there is a value in it  and if it is null its not printing drillDateTime.

Note: drillTime is text and drillDateTime is date and time type.

 

4 replies

mathieud0001
Genius
Apr 4, 2022 12:58 PM UTC
Participating Frequently
Apr 5, 2022 10:34 AM UTC

Thanks for your reply but the link you provided is not helpful for me.

acaciob0002
Participating Frequently
Apr 6, 2022 12:09 AM UTC

Hi vamsikrishnac0001,

In my understanding, when you are using an Else IF condition, you need to also provide an ELSE, can you please have a look in the code below and see if it can help you?

[#if dmd.drillTime?has_content]
${dmd.drillTime!""}
[#elseif dmd.drillDateTime?has_content]
${dmd.drillDateTime??}
[#else]
Add the condition for the else
[/#if]

Regards,

Acacio B.

Participating Frequently
Apr 6, 2022 5:34 PM UTC

Thank you very much [mention:b389a349840947d58879708f8b0249f2:e9ed411860ed4f2ba0265705b8793d05]

I have already figured out the code.

  1. [#if dmd.drillTime??]
    [#if dmd.drillTime!=""]
    ${dmd.drillTime!""}
    [elseif dmd.drillDateTime??]
    ${dmd.drillDateTime!""}
    [/#if]
    [/#if]