How to render flash messages

ayhamhsn - 5 months ago

I used to define an instance of a form builder and rendered its inputs in my structure. but when I want to render the flash messages comes from the response of form in case it success or there are some errors. this is what I have done :

      <div class="contact-form f-san-light">
                {% set form  = form('contactus').to('[email protected]').get() %}
                {{ form.open({'class' : 'contact-form', 'id' : 'main-contact-form'}) |raw }}
                    <div class="form-group wow fadeInLeft mar9">
                        {{ form.fields.name.input |raw }}
                    </div>
                    <div class="form-group wow fadeInLeft mar9">
                        {{ form.fields.company_name.input |raw }}
                    </div>
                    <div class="form-group drop wow fadeInLeft mar9">
                        {{ form.fields.country.input |raw }}
                    </div>
                    <div class="form-group wow fadeInLeft mar30">
                        {{ form.fields.address.input |raw }}
                    </div>
                    <div class="form-group wow fadeInLeft mar9">
                        {{ form.fields.mobile_number.input |raw }}
                    </div>
                    <div class="form-group wow fadeInLeft  mar30">
                        {{ form.fields.email.input |raw }}
                    </div>
                    <div class="form-group drop wow fadeInLeft mar9">
                        {{ form.fields.subject.input |raw }}
                    </div>
                    <div class="form-group wow fadeInLeft mar9">
                        {{ form.fields.message.input |raw }}
                    </div>
                    <div class="form-group wow fadeInLeft">
                        <button type="submit" class="submit btn primary-color-background f-header-bold">SUBMIT</button>
                    </div>
                {{ form.close |raw }}

            </div>

Answer

- 5 months ago

{% if message_exists('success') %}
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">
            <span>&times;</span>
        </button>
        {% for message in message_get('success') %}
            {{ trans(message)|markdown }}
        {% endfor %}
    </div>
{% endif %}

An example of multiple types of messages can be found in {% if message_exists('success') %} <div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert"> <span>&times;</span> </button> {% for message in message_get('success') %} {{ trans(message)|markdown }} {% endfor %} </div> {% endif %}

dominique - 5 months ago

{% if message_exists('success') %}
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">
            <span>&times;</span>
        </button>
        {% for message in message_get('success') %}
            {{ trans(message)|markdown }}
        {% endfor %}
    </div>
{% endif %}

An example of multiple types of messages can be found in {% if message_exists('success') %} <div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert"> <span>&times;</span> </button> {% for message in message_get('success') %} {{ trans(message)|markdown }} {% endfor %} </div> {% endif %}

jcastillotx - 5 months ago

There is a notification partial in the template you can use. Just call it in the twig.