PHP Classes

File: examples/custom.php

Recommend this page to a friend!
  Classes of Yuriy Tkachenko  >  Simple Flash Messages  >  examples/custom.php  >  Download  
File: examples/custom.php
Role: Example script
Content type: text/plain
Description: Demo Custom
Class: Simple Flash Messages
Display message with different CSS frameworks
Author: By
Last change: Update for version 2.0
Date: 11 months ago
Size: 2,286 bytes


Class file image Download

use Tamtamchik\SimpleFlash\BaseTemplate;


__DIR__ . '/../vendor/autoload.php';

CustomTemplate extends BaseTemplate implements TemplateInterface
$prefix = '<li>'; // every line prefix
protected $postfix = '</li>'; // every postfix
protected $wrapper = '<ul class="a a-%s">%s</ul>'; // wrapper over messages of same type

     * @param $messages - message text
     * @param $type - message type: success, info, warning, error
     * @return string
public function wrapMessages($messages, $type)
sprintf($this->getWrapper(), $type, $messages);

flash()->setTemplate(new CustomTemplate)->error(['Invalid email!', 'Invalid username!'])
warning('Warning message.')
info('Info message.')
success('Success message!');


<!doctype html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Test custom template example.</title>

        .container {
            max-width: 600px;
            margin: 0 auto;
            font-family: -apple-system, --sans-serif, sans-serif;
        .a {
            border: 1px solid;
            border-radius: 10px;
            padding: 1em;
            margin: 0.25em 0;

        .a li {
            list-style: none;

        .a-info {
            background: lightblue;

        .a-error {
            background: lightpink;

        .a-warning {
            background: lightgoldenrodyellow;

        .a-success {
            background: lightgreen;

<a href=""><img style="position: absolute; top: 0; right: 0; border: 0;" src="" alt="Fork me on GitHub" data-canonical-src=""></a>

<div class="container" style="width: 600px;">

    <?php include_once '_menu.php'; ?>

    <?= flash() ?>



For more information send a message to info at phpclasses dot org.