2016-12-08 77 views
1

我需要處理[CDATA]標記內部的html定位點和目標標記。我的freemarker版本是2.3.18。如何處理在ftl中的CDATA標記中指定的html定位標記(freemarker)

請指教如何使用freemarker轉義或無轉義標記來處理此問題。當我嘗試添加轉義標記時,值未達到ftl。不知道我是否做錯了。

<#assign cDataStart="<![CDATA["> 
    <#assign cDataEnd="]]>"> 
    <tr class="planHeading"> 
    <#assign xlist = plan.column> // plan.column is list of strings 
     <#list xlist as x> 
     <h2 id="planMed"> 
      ${cDataStart}${x?replace("<br>", cDataEnd+"<br />"+cDataStart)}${cDataEnd} // x consist "You pay INR 0.00 <br>**For more information regarding, please click <a href=https://www.example.com/a.pdf target=_blank>here</a>." 
     </h2> 
     </#list> 
    </tr> 

爲$ {X}的預期輸出:

"You pay INR 0.00 <br>**For more information regarding, please click here" 

電流輸出:

"You pay INR 0.00 <br>**For more information regarding, please click <a href=https://www.example.com/a.pdf target=_blank>here</a>" 

回答

0

使用${x?no_esc}

或者,你可以關閉自動轉義爲整個模板,在第一行加入

<#ftl autoesc=false> 

有關更多詳細信息,請參見http://freemarker.org/docs/dgui_misc_autoescaping.html

+0

當我添加$ {x?no_esc}時,該值未達到ftl並觸發異常。問題有點不同,理解有點遲。我相應地修改了問題和desc。請指教。 – RVR