RE: 7.1 - How to avoid escaping in freemarker template?

thumbnail
Mirto Silvio Busico, modified 7 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts

Hi all,

I'm trying to create a freemarker template for a DDL list.

One field contain HTML and is of  "ddm-text-html" type (eg "Text1")

 

This code

Text HTML: ${ddlDisplayTemplateHelper.renderRecordFieldValue(cur_record.getDDMFormFieldValues("Text1")?first, locale)}

gives as output

Text HTML:&nbsp;<a>(Preview)</a>&nbsp;

so I obtain a link to a pop-up window containing the HTML

 

This code

&lt;#escape x as x?html&gt;<br> &lt;#noescape&gt;<br> &nbsp;${ddlDisplayTemplateHelper.getHTMLContent(cur_record.getDDMFormFieldValues("Text1")?first, locale)}<br> &lt;/#noescape&gt;<br> &lt;/#escape&gt;

gives this output

\x3cp\x3e\x0a\x20\x20\x3cstrong\x3eTo\x20choose\x20a\x20parent\x20definition\x2c\x20click\x20the\xa0\x3c\x2fstrong\x3e\x3c\x2fp\x3e\x0a

 

Trying to use only <#noescape>...</#noescape> gives the error

2018-08-23 12:36:28.450 ERROR [http-nio-8080-exec-8][IncludeTag:128] Current URL /web/guest/4ddl generates exception: com.liferay.portal.kernel.templateparser.TransformException: Unhandled exception<br> freemarker.core.ParseException: Syntax error in template "20099#20135#44379" in line 11, column 33:_#noescape with no matching #escape encountered. [Sanitized]

 

How can I render HTML in templates?

 

 

 

 

 

thumbnail
Achmed Tyrannus Albab, modified 6 Years ago. Regular Member Posts: 158 Join Date: 3/5/10 Recent Posts
Hi, Are we the only two guys with this issue?
I don't remember having this problem in previous version.
Did you manage?My script are as follows :
#if(!$records.isEmpty())
&nbsp;&nbsp;&nbsp;&nbsp;#foreach ($cur_rec in $records )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#set ($someHTML= $ddlDisplayTemplateHelper.getHTMLContent($cur_rec.getDDMFormFieldValues("HTMLField").get(0), $locale))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XXX $someHTML XXX&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;#end
#end

What i entered for the DDL :
<p><b>asdasdsadsa sdasdsa asdasdsa</b></p>
And my results are :
XXX \x3cp\x3e\x0a\x20\x20\x3cb\x3easdasdsadsa\x20sdasdsa\x20asdasdsa\x3c\x2fb\x3e\x3c\x2fp\x3e\x0a XXX&nbsp;

Any help on how to show the actual HTML?
​​​​​​​Cheers.
thumbnail
Achmed Tyrannus Albab, modified 6 Years ago. Regular Member Posts: 158 Join Date: 3/5/10 Recent Posts
Hi Mirto Silvio Busico ,

Did you manage to solve this issue?
thumbnail
Achmed Tyrannus Albab, modified 6 Years ago. Regular Member Posts: 158 Join Date: 3/5/10 Recent Posts
Hi, I found a solution (at least for my issue) here : https://liferay.dev/forums/-/message_boards/message/117396471 . Hope it helps.
thumbnail
Mirto Silvio Busico, modified 6 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts
Sorry,I was busy on other technologies and I'm returning now.I'll liik at your solution asap