We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Styling of flash messages

Default the flash messages are displayed like this - <div class="errorMessage"> Message comes here</div> but i want that text only .... is there any way to get message without div?

Normally I have {{ flash.output() }} in my layout.

If I change this to flash.getMessages() I get an array with messages grouped by type. Maybe this works for you too.

It's in the documentation https://docs.phalcon.io/en/latest/reference/flash.html

<?php

//Register the flash service with custom CSS classes
$di->set('flash', function(){
    $flash = new \Phalcon\Flash\Direct(array(
        'error' => 'alert alert-error',
        'success' => 'alert alert-success',
        'notice' => 'alert alert-info',
    ));
    return $flash;
});

The messages would be printed:

<div class="alert alert-error">too bad! the form had errors</div>
<div class="alert alert-success">yes!, everything went very smoothly</div>
<div class="alert alert-info">this a very important information</div>

You can change the class or write nothing if you want.

edited Feb '17

If you want to generate some mark-up around it. I found this on the Cphalcon repo on Github

{# .volt #}

    {% for type, messages in flash.getMessages() %}
            <div class="box-body">
                {% for message in messages %}
                    <div class="alert alert-{{ type }}">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h4>{{ message }}</h4>
                    </div>
                {% endfor %}
            </div>
    {% endfor %}