tags:

views:

230

answers:

2

I'm using freemarker to generate a freemarker template. But I need some way to escape freemarker tags.

How would I escape a <#list> tag or a ${expression} ?

+1  A: 

You can use raw string literals to escape expressions and &lt; / &gt; to escape directives:

${r"${expression}"}
&lt;#list&gt;

will print

${expression}
<#list>
ChssPly76
When freemarker process the file it keeps with < and >
tuler
${r"${expression}"} works
tuler
I seem to remember it worked for me. But if not, you can always use ${r"<#list>"} instead.
ChssPly76
+1  A: 

I'm using the alternative syntax feature. I start the template with [#ftl] and use this syntax.

For the expressions I use the string literal feature: ${r"${expression}"}

tuler
I use the same approach, which is a bit ugly but works. It gets really nasty if I use a variable of the outer template to define the property access of a variable of the generated template, which looks like this: ${r"${entity."}${propertyDescriptor.name}}and ends like ${entity.creationDate}given that the propertyDescriptor has the name "creationDate".
Peter Becker