I am working on a freemarker template and here is a sample.
<Grantor> <UniqueID>${(currentGrantorIndex)!?string}</UniqueID> // want to comment this line <Entity>${(grantor.entityTypeName)!?string}</Entity> </Grantor>
I want to know how to write comments or comment out few lines in freemarker templates. Any idea?
Comments: <#-- and --> Comments are similar to HTML comments, but they are delimited by <#-- and -->. Comments will be ignored by FreeMarker, and will not be written to the output.
FreeMarker is a template engine, written in Java, and maintained by the Apache Foundation. We can use the FreeMarker Template Language, also known as FTL, to generate many text-based formats like web pages, email, or XML files.
If you want to insert the value of an expression into a string, you can use ${...} (and the deprecated #{...} ) in string literals. ${...} in string literals behaves similarly as in text sections (so it goes through the same locale sensitive number and date/time formatting).
eval. This built-in evaluates a string as an FTL expression. For example "1+2"? eval returns the number 3. (To render a template that's stored in a string, use the interpret built-in instead.)
Comment in freemarker are delimited by <#--
and -->
. Everything between these delimiters will not be interpreted by freemarker and won't appear in the output.
<Grantor> <#-- <UniqueID>${(currentGrantorIndex)!?string}</UniqueID> --> <Entity>${(grantor.entityTypeName)!?string}</Entity> </Grantor>
See freemarker reference here.
Another non-standard way of adding comments in freemarker using the if tag:
<#if 1=0>comment</#if>
or
<#if false>comment</#if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With