Reputation: 3482
I cannot get the Flash message to appear in an element or in a layout. However, it works fine in a template.
I have the following code in my element, layout and template:
<?= $this->Flash->render();?>
When I create an error, it displays fine when called from a view, but it doesn't work from an element or my layout file.
The idea is to load the Flash message on top of a form, that is generated using an element in the left side nav in my layout.
Upvotes: 2
Views: 269
Reputation: 3482
It would appear that calling more than one Flash->render()
clears the session for the other subsequent calls.
I just have to figure out the best way to limit which Flash->render()
to call. For instance, wrapping the Flash->render()
in an if statement in my element. There's also the possibility to key individual Flash messages that I'm investigating.
My solution
Setting the flash:
$this->Flash->error(__('Invalid credentials, try again'), ['key' => 'element']);
In my element:
<?= $this->Flash->render('element')?>
Upvotes: 1