I'm porting a code from a template override of com_content category blog_item into a module.
Everything is all right done, except for one thing I'm struggling with.

I have this code from com_content tmpl:

<?php echo $this->item->event->beforeDisplayContent; ?>

In the module I tried:

<?php echo $item->event->beforeDisplayContent; ?>

But it is not working and it fires a notice ("Notice: Trying to get property of non-object...")

Any suggestion to have it working into a module?

1 Answer 1


I have no idea about how you build your module and what the $item stands for there.

Assuming you are loading the articles using the com_content's model and you have an array of $items with each $item being an Article Object, returned by the ContentModel, then you can do at the top of your module's template:

$dispatcher = JEventDispatcher::getInstance();

Then in your loop of the $items (since you said you are porting over a category blog, I guess you will have a list of articles).

foreach ($items as $item) {

    // Get everything from the enabled OnContentBefore plugins in an array
    // passing the $item and $params as reference
    $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$item->params, 0)); 

    $beforeDisplayContent = trim(implode("\n", $results));

    echo $beforeDisplayContent . ' - ' . $item->title;


More reading: JPlugin Documentation:

  • Thanks for your answer. The module is essentially the mod_article_latest plus some js and a different template. So I think your solution is correct: adding the code from view.html.php of com_content . Now I'm trying to make it work.
    – N.Fury
    Commented Jul 1, 2016 at 21:48
  • Then you should be fine with the code above. If my answer solved your problem, mark it as accepted answer (joomla.stackexchange.com/help/someone-answers, joomla.stackexchange.com/help/why-vote) @N.Fury
    – FFrewin
    Commented Jul 2, 2016 at 6:21
  • starting from your code I did this into the loop: $item->event = new stdClass(); $item->event->beforeDisplayContent = trim(implode("\n", $results)); and now I can use "<?php echo $item->event->beforeDisplayContent; ?>" into the tmpl/default.php It not automatically render the plugin, but I can add a shortcode via the article editor, like this {maxivote} and everything's all right !!!
    – N.Fury
    Commented Jul 2, 2016 at 15:25

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.