Here is a how you can display all your flash bag messages in a Symfony Twig view.  The “flash bag” is a special collection of session variables that hold data like a one-time message in HTML.  It is often used in e-commerce form flows when the credit card was declined, instead of further processing the payment, the rejection of the credit card appears in your TWIG view so the user can read the message and act on it.

Perhaps it will say “Credit card was denied, please check your billing ZIP code.”  or another frequent issue happens when the user fails to put in the appropriate number of credit card digits, you can have your controller put in the flash bag the message:  “Credit card requires 15 digits for AMEX, 16 digits for all other cards.”

{% for label, flashes in app.session.flashbag.all %}

    {% for flash in flashes %}

        <div class="alert alert-{{ label }}">

            {{ flash }}

        </div>

    {% endfor %}

{% endfor %}

 


Strange how obscure it is to find a clear example of how to just access or show the value of a cookie in Twig, so here it is!

{{      app.request.cookies.get('yourCookieHere')  }}

Twig is the templating engine that powers Symfony views.  Symfony is the PHP framework from Sensio Labs.

If you are a company that uses open-source software and developers and you are not using a PHP framework, you should consider migrating your legacy “cowboy” code to a collaborative, scalable framework like Symfony before it becomes a necessity for your company.  I have overseen many migrations of systems and data over the years and am available for consultation at my business consulting site at Belchamber.us.

– Aaron Belchamber