FlashMessages ViewHelper <f:flashMessages>

This ViewHelper renders the Flash messages (if there are any) as an unsorted list.

Screenshot of two flash message one with success and one with warning severity

Example for the output of flash messages in an Extbase plugin

Go to the source code of this ViewHelper: FlashMessagesViewHelper.php (GitHub).

Quick start: Simple flash message output

You can use the following tag within any Extbase template:

packages/my_extension/Resources/Private/Templates/Something/DoSomething.html
<f:flashMessages />
Copied!

It displays the flash messages with a standard bootstrap compatible layout.

Adding and displaying flash messages in Extbase

Within an Extbase controller (extending ActionController ) you can call method addFlashMessage() to add flash messages to the message queue:

packages/my_extension/Classes/Controller/MyController.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Controller;

use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class MyController extends ActionController
{
    public function demonstrateFlashMessagesAction(): ResponseInterface
    {
        $this->addFlashMessage('This is a success message.');
        $this->addFlashMessage('This is a warning.', 'Warning Headline', ContextualFeedbackSeverity::WARNING);
        return $this->htmlResponse();
    }
}
Copied!

As mentioned above, they will be displayed when a <f:flashMessages> is displayed within any action of the same controller:

packages/my_extension/Resources/Private/Templates/My/DemonstrateFlashMessages.html
<f:layout name="MyLayout"/>
<f:section name="Content">
    <f:flashMessages />
</f:section>
Copied!

If you want to display the flash messages in any place outside of the controller you can use the identifier extbase.flashmessages.<pluginNamespace>, for example:

packages/my_extension/Resources/Private/Templates/Other/SomeForm.html
<f:layout name="MyLayout"/>
<f:section name="Content">
    <f:flashMessages queueIdentifier="extbase.flashmessages.tx_myextension_myplugin"/>
</f:section>
Copied!

Using a specific flash message queue in plain classes

When you use the FlashMessages ViewHelper outside of the Extbase context, supplying the queueIdentifier is mandatory.

When you add a message manually to the queue, you can specify an arbitrary identifier:

// private \TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService;

$messageQueue = $this->flashMessageService->getMessageQueueByIdentifier('myQueue');
Copied!

You can then display messages of only this one queue using the identifier:

<f:flashMessages queueIdentifier="myQueue" />
Copied!

Output flash messages with a custom layout

Using the argument as you can receive all flash messages in a variable and then handle the rendering yourself within the <f:flashMessages> tag:

packages/my_extension/Resources/Private/Templates/Something/DoSomething.html
<f:flashMessages as="flashMessages">
  <dl class="messages">
    <f:for each="{flashMessages}" as="flashMessage">
      <dt>{flashMessage.code}</dt>
      <dd>{flashMessage.message}</dd>
    </f:for>
  </dl>
</f:flashMessages>
Copied!

Argument of the FlashMessages ViewHelper

as

as
Type
string
The name of the current flashMessage variable for rendering inside

queueIdentifier

queueIdentifier
Type
string
Flash-message queue to use