How do you customize the HTML template for flash

Nov '14

Aug '16





You must to create a custom class inheriting from Phalcon\Flash\Direct to alter the message adding the close div:

    class MyFlash extends Phalcon\Flash\Direct
        public function message($type, $message)
            $message .= ' <div class="close"></div>';
            parent::message($type, $message);

Then, you must to setup it in file autoload

    $di->set('flash', function(){
        return new MyFlash();

Or, you can adding button code to your message:

$this->flash->success('<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>My Message');

This is great trick and works great for me until upgrade to phalcon 2.1.x, the trick won't work well because of autoescape,

To get it solved, you have to disable autoescape, so the extra html is not coverted to html entity.

    $di->set('flash', function(){
        $flash = new MyFlash();
        return $flash;