Search code examples
htmlphalconvolt

Phalcon Volt turns html code into string


I have html code from my db and I'm trying to print it as {{ blog.content }}. But it renders as string and shows all the html tags etc. How can I make it to render as html?

it looks like:

<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 shouldn't be visible. The line above should be rendered as html. Which means bold parts example; should be bold.


Solution

  • 1) Create Elements.php (Library or Plugin all are same)

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

    2) Add Elements.php to the service

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

    3) In Volt File Try this

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

    Hope It Works.. :)