Phalcon Volt 将 html 代码转换为字符串

Phalcon Volt turns html code into string

我的数据库中有 html 代码,我正在尝试将其打印为 {{ blog.content }}。但它呈现为字符串并显示所有 html 标签等。我怎样才能让它呈现为 html?

看起来像:

<p>I am writing my blog post here to show everyone that I can do such things as this: <span style="font-weight: bold; font-family: Impact; font-size: 36px;">adsdsfadsf&nbsp;</span><span style="font-size: 11px; background-color: yellow;">and also like this one</span></p>

html标签不应该可见。上面的行应该呈现为 html。这意味着粗体部分示例;应该加粗。

1) 创建Elements.php(库或插件都一样)

namespace YourAppNameSpace;

use Phalcon\Config;

class Elements extends \Phalcon\Mvc\User\Plugin
{
     public function decodeString($string)
    {
        return html_entity_decode($string);
    }
}

2) 添加Elements.php到服务

$di->set('element', function () {
    return new YourAppNameSpace\Elements();
});

3) 在 Volt 文件中试试这个

{{ element.decodeString(blog.content) }}

希望有用..:)