通过 Smarty 从 PHP 数组渲染 HTML


Render HTML from PHP array via Smarty

这是一个 Smarty 模板文件的内容...

{foreach from=$productcustomfields item=customfield}
<tr>
  <td class="fieldarea">{$customfield.name}:</td>
  <td>{$customfield.value}</td>
</tr>
{/foreach}

当 {$customfield.value} 在屏幕上呈现时,该数组值中的任何 HTML 标记都将在浏览器中显示为纯文本。如何让 Smarty 实际呈现 HTML 标签,而不是将它们作为文字文本?

例如,如果值为 $customfield.value 是...

<strong>Hello</strong>

它会在浏览器中看起来就像那样,而不是应有的 Hello

尝试使用

{$customfield.value nofilter}

(见参考资料)