Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: 7.1 - How to avoid escaping in freemarker template?
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: <a>(Preview)</a>
so I obtain a link to a pop-up window containing the HTML
This code
<#escape x as x?html><br> <#noescape><br>
${ddlDisplayTemplateHelper.getHTMLContent(cur_record.getDDMFormFieldValues("Text1")?first,
locale)}<br> </#noescape><br> </#escape>
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?
I don't remember having this problem in previous version.
Did you manage?My script are as follows :
#if(!$records.isEmpty())
#foreach ($cur_rec in $records )
#set ($someHTML= $ddlDisplayTemplateHelper.getHTMLContent($cur_rec.getDDMFormFieldValues("HTMLField").get(0), $locale))
XXX $someHTML XXX
#end
#endWhat 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 Any help on how to show the actual HTML?
Cheers.
Did you manage to solve this issue?