Hi Freemarker Devs,

I have a question about the Autoescaping and the outputformat, 
https://freemarker.apache.org/docs/dgui_misc_autoescaping.html

Examplecode:

<#ftl output_format="HTML">

<#outputformat "plainText">
<#function testFunction>
<#local result><@testMacro /></#local>
<#return result />
</#function>
</#outputformat>

<#outputformat "plainText">
<#macro testMacro>
&
</#macro>
</#outputformat>

Test Function: ${testFunction()}
Test Macro: <@testMacro/>

Output:

Test Function: &amp;
Test Macro: &

It looks like outputformat is not working surrounding a function. The simplest 
fix is to add ?no_esc to the call:
${testFunction()?no_esc}

But we have a lot of calls of this function and don't want to change all 
templates.

So I tried this code (without outputformat):

<#ftl output_format="HTML">

<#function testFunction>
<#local result><@testMacro /></#local>
<#return result />
</#function>

<#outputformat "plainText">
<#macro testMacro>
&
</#macro>
</#outputformat>

Test Function: ${testFunction()}
Test Macro: <@testMacro/>

Output:

Test Function: &
Test Macro: &

Why does it work without the ouputformat surrounding the function? Or maybe, 
why does the outputformat do the opposite to the function?

Thank you,
Michael Riehemann

Reply via email to