How to Display Messages and Notices in Joomla

Messages, errors, warnings and notices can be displayed from any component, module, plugin or template. The messages use the standard bootstrap CSS styles for alerts.

use Joomla\CMS\Factory;
$app = Factory::getApplication();

$app->enqueueMessage(Text::_('SOME_ERROR_OCCURRED'), 'error');

The second argument to the enqueueMessage() method is the type of the message. The default is 'message', but 'error' results in a different style for the message.

Where it is displayed?

The message is displayed in place of a special jdoc:include statement in the template. Place the following in your template at the location where you want messages to appear:

<jdoc:include type="message" />