Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comments in freemarker template and smooks

Tags:

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?

like image 852
SikanderAhmed Avatar asked Dec 03 '13 10:12

SikanderAhmed


People also ask

How do I comment in FreeMarker template?

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.

What is the use of FreeMarker template?

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.

How do you add values on FreeMarker?

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).

What is eval in FreeMarker?

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.)


2 Answers

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.

like image 120
obourgain Avatar answered Sep 18 '22 14:09

obourgain


Another non-standard way of adding comments in freemarker using the if tag:

<#if 1=0>comment</#if> 

or

<#if false>comment</#if> 
like image 39
Rohit Avatar answered Sep 22 '22 14:09

Rohit