I would like to render Joomla messages inside a component Template because the index.php doesn't fit my needs.
So how do I simulate <jdoc:include type="message" />
inside /templates/<tmpl>/html/com_content/article/default.php
for example.
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It only takes a minute to sign up.
Sign up to join this communityYou could also override the default layout for system messages.
To do so, copy the following file:
ROOT/layouts/joomla/system/message.php
to:
ROOT/templates/TEMPLATE_NAME/html/layouts/joomla/system/message.php
You can also use Joomla's loadRenderer
function in the component view.
In the view file, add the following:
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('message');
Then for a test, add the following to enqueue a message in the session:
$app = JFactory::getApplication();
$app->enqueueMessage('test message');
Then anywhere in your view, add the following to output the message:
$renderer->render('message');
One way to do this is to use JDocument::getBuffer('message');
in html/com_content/article/default.php
<?php
echo $this->document->getBuffer('message')
?>
This will also clear the message buffer.
Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below.
// Get a handle to the Joomla! application object
$application = JFactory::getApplication();
// Add a message to the message queue
$application->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
/** Alternatively you may use chaining */
JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
Know more from https://docs.joomla.org/Display_error_messages_and_notices