FREEMARKER: Avoid Avoiding HTML Characters

Having a problem with freemarker exit ...

                [#assign optionsHTML = ""]                    
                [#list data as item]
                    [#assign optionsHTML = optionsHTML + '<option value="' + item.value +'>'+ item.label + '</option>' /]
                [/#list]

so if i do

<select>
${iptionsHTML}
</select>

the output from otions gets html objects instead of the actual html .... so

&lt;option value=&quot .....

even if i do

            [#assign optionsHTML = ""]                    
            [#list data as item]
                [#noescape]
                [#assign optionsHTML = optionsHTML + '<option value="' + item.value +'>'+ item.label + '</option>' /]
                [/#noescape]
            [/#list]

even tried

<select>
${iptionsHTML?html}
</select>

but worse: (

+4
source share
3 answers

So, after I tried things, I don’t know what I did wrong before, but clean, this method works

[#assign optionsHTML = ""]                    
[#list data as item]
   [#assign optionsHTML = optionsHTML + '<option value="' + item.value +'>'+ item.label + '</option>' /]
[/#list]



<select>
   [#noescape]
   ${optionsHTML}
   [/#noescape]
</select>
+2
source

The room #noescapearound is #assignnot affected. Auto-escaping applies only to ${...}-s, which are embedded directly in static text (HTML). Thus, there is no way to shield inside #assign.

?html "". , optionsHTML = optionsHTML + '<option value="${item.value?html}>${item.label?html}</option>', , , ${...} -s .

, , , HTML, HTML, , HTML . , FTL.

+2

As ddekany said, write something like this:

<select>
  [#list data as item]
    <option value="${item.value}">${item.label}</option>
  [/#list]
</select>
0
source

Source: https://habr.com/ru/post/1543878/


All Articles