3

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.

3 Answers 3

5

You 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

Update:

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');
3
  • Sorry it's not the question how to change the layout of the messages. The question is where to output the html code with the message. Aug 24, 2015 at 11:09
  • @HaraldLeithner - My bad, didn't read the question properly. I've updated the answer
    – Lodder
    Aug 24, 2015 at 11:27
  • much better thc Aug 24, 2015 at 11:36
4

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.