Friday, July 14, 2017, 4:02:31 PM, Riehemann, Michael wrote:
> Hi Daniel,
>
> thanks for the fast answer! Just in the moment of sending my
> question I found ?markup_string...
>
>> Are you perhaps using #macro where you should use #function?
> You are right. We're using spring.ftl and they use macros
> everywhere (see
> https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/resources/org/springframework/web/servlet/view/freemarker/spring.ftl
> ), so we need to wrap it to functions :(
There's another approach which might be more convenient in that case:
<#output_format 'plainText'>
<#function foo>
<#local out><@spring.foo/></#local>
<#return out>
</#function>
... several other similar functions here ...
</#output_format>
> Thanks again
> Michael
>
> -----Ursprüngliche Nachricht-----
> Von: Daniel Dekany [mailto:[email protected]]
> Gesendet: Freitag, 14. Juli 2017 15:51
> An: Riehemann, Michael <[email protected]>
> Cc: [email protected]
> Betreff: Re: Question to Freemarker Escaping
>
> Friday, July 14, 2017, 3:14:28 PM, Riehemann, Michael wrote:
>
>> Hi Freemarker Devs!
>>
>> We are using Freemarker since years and changed our old templates with
>> no output format to output format HTML to get rid of all the "?thml" and
>> "<#escape/> parts.
>>
>> Everything is fine so far, except that some typical things stopped
>> working, because some variables are now markup_output instead of
>> string. So we can't use Built-ins for strings on them anymore. See
>> example below. What can we do? Do we need the same Built-ins for
>> markup_output? Can we cast markup_output back to string?
>
> You can get the markup behind a markup_output as a string via
> ?markup_string:
> http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_markup_string
>
> Be careful, the result of ?markup_string is just a string and so is
> subject to auto-escaping again. That's one reason why captured output is not
> a string.
>
> However, it should be very rare that you want to do string
> manipulation or comparison on captured output. It mostly only meant
> to be reprinted. Markups tend to have many ways of describing the
> same thing (like <foo a="1" b="2"/> is equivalent to <foo b='2'
> a="1"/>, yet as strings they differ). Also they are easily corrupted
> by most string operations (like when you get a substring, you may
> end up with unclosed elements). Are you perhaps using #macro where you should
> use #function?
>
>> Any help is appreciated.
>>
>> Thanks
>> --Michael Riehemann
>>
>>
>>
>> Example:
>> <#ftl output_format="HTML">
>>
>> <#macro smallTest text>
>> ${text}
>> </#macro>
>>
>> <#assign smallTestResult><@smallTest "test" /></#assign>
>>
>> <#if smallTestResult == "test">
>> smallTestResult: ${smallTestResult}
>> </#if>
>>
>> Result:
>> Can't compare values of these types. Allowed comparisons are between
>> two numbers, two strings, two dates, or two booleans.
>> Left hand operand is a markup_output (wrapper: f.c.TemplateHTMLOutputModel).
>> Right hand operand is a string (wrapper: f.t.SimpleScalar).
>> The blamed expression:
==>>> smallTestResult == "test" [in nameless template at line 9, column 6]
>
> --
> Thanks,
> Daniel Dekany
>
>
--
Thanks,
Daniel Dekany