如何在NetSuite高级PDF/HTML模板中渲染富文本字段的HTML内容?
在NetSuite Advanced PDF/HTML模板中渲染自定义富文本字段的HTML内容
问题背景
我在Item Fulfillment上创建了富文本类型的自定义字段custbody_monthly_promo,字段内的HTML内容为:
<p><strong>Special Offer:</strong> Get 20% off this month!</p>
尝试用以下代码在Advanced PDF/HTML模板中渲染该字段:
<table class="monthlyPromo"> <tr> <td> <#if record.custbody_monthly_promo?has_content> <#assign myhtml = record.custbody_monthly_promo?interpret> <@myhtml> </#if> </td> </tr> </table>
但生成的PDF中该区域显示空白。已完成以下排查:
- 确认字段已正确填充HTML内容
- 用
${record.custbody_monthly_promo}测试可获取原始HTML标签,但无法渲染成格式化文本 - 验证字段ID
custbody_monthly_promo无误
需求是将富文本字段中的HTML内容渲染为格式化文本(如Special Offer: Get 20% off this month!),不显示原始标签。
解决方案
方法1:使用?no_esc过滤器输出未转义的HTML
NetSuite的Advanced PDF模板基于FreeMarker,富文本字段的内容会被自动转义,导致HTML标签无法被解析。使用?no_esc过滤器可以关闭转义,让PDF渲染引擎直接解析HTML内容:
<table class="monthlyPromo"> <tr> <td> <#if record.custbody_monthly_promo?has_content> ${record.custbody_monthly_promo?no_esc} </#if> </td> </tr> </table>
此方法直接输出未转义的原始HTML,PDF引擎会解析<strong>、<p>等常见标签并生成对应格式的文本。
方法2:处理转义异常的内容
如果富文本字段的内容存在额外转义(比如用<代替<),需要先通过?html过滤器反转义,再用?no_esc输出:
<table class="monthlyPromo"> <tr> <td> <#if record.custbody_monthly_promo?has_content> ${record.custbody_monthly_promo?html?no_esc} </#if> </td> </tr> </table>
注意事项
- NetSuite默认PDF引擎仅支持常见HTML标签(
<p>、<strong>、<em>、<br>等),复杂CSS或JavaScript无法被解析 - 若仍无法渲染,可通过
${record.custbody_monthly_promo}输出原始内容,确认是否存在格式异常或未预期的包裹标签
内容的提问来源于stack exchange,提问作者Amit Kadlag
相关产品推荐
相关产品推荐

