Andrei Herford Andrei Herford - 9 months ago 98
PHP Question

How to use HTML tags in Symfony flash message

working with Symfony 2.7 I would like to include HTML in a flash message:

class MyController extends Controller {
public function someAction(Request $request) {
$this->addFlash('success', $tranlator->trans('some.success.msg', array(), 'app'));

// app.yml
msg: Text with some <strong>HTML</strong>

This creates a Flash Message

Text with some <strong>HTML</strong>

instead of

Text with some HTML

Within my own Twig template I would use the
filter, to display the HTML code directly instead of the escaped version. But how can I achive the same within

Answer Source

I think this cannot be done directly. But you can tweak where you are showing the message using some html and css.


In setting the flash message:

$this->get('session')->getFlashBag()->add('notice', array('type' => 'success', 'title' => 'Done!', 'message' => 'OK! It is done!'));

And in twig file:

{% for msg in app.session.flashbag.get('notice') %}
<div class="alert alert-{{ msg.type }}">
    <strong>{{ msg.title }}</strong><br/>{{ msg.message }}
{% endfor %}