0

私のデータベースから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>

htmltags は表示されません。上記の行は、html としてレンダリングする必要があります。つまり、太字部分の例です。大胆であるべきです。

4

1 に答える 1

2

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) }}

それがうまくいくことを願っています.. :)

于 2015-08-14T12:54:14.383 に答える