Search code examples
javascriptphpcsscakephpcakephp-3.x

Appliying style to flash messages in CakePHP 3


Hi i work on CakePHP3 project,

After changing the default.ctp by new template the Flash messages are shown without any style , how can i apply a style to show it as before..

Here is thee block of Flash Message :

// in view   
 <?php echo $this->Flash->render(); ?>

Solution

  • Styling is done via CSS - In case you removed the default Cake.css in your customized layout file default.ctp you probably have to add the styling in your own css file.

    The default css classes for the flash messages are located in /app/scr/Template/Element/Flash.

    As you can see in the files the cointaining div has the class "message" and the styling for this class is defined in the Cake.css here

    You can also add your own error layout with custom classes or overwrite the default classes as it is also mentioned in the docs. So please also read the docs about the flash component and about rendering flash messages...