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
some:
success:
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 raw
filter, to display the HTML code directly instead of the escaped version. But how can I achive the same within addFlash(...)
?
Not sure i really understand your question. If this is not what you're asking just say it and I will remove this answer.
As said in documentation you use
app.session.flashbag.get('success')
to retrieve your flash message. Example :
{% for flash_message in app.session.flashbag.get('success') %}
{{ flash_message|raw }}
{% endfor %}
I think this cannot be done directly. But you can tweak where you are showing the message using some html and css.
Like:
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 }}
</div>
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With