InMotion Hosting Support Center
This is archived and no longer maintained. Any information contained in this article may be out of date.

Joomla 2.5 has reached its end of life as for 12/31/2014. Please be advised this may be a security risk to your website. You can view more information about the end of life here.

When creating a Joomla 2.5 content plugin, there are several events at which you can run your code. For example, the hook we've been using in our testing thus far has been onContentAfterTitle, which allows us to run code immediately after the title of the article has been displayed. In this tutorial, we'll look at the various events you can trigger your code at within a content plugin.

How are the plugin events triggered?

Content plugins are triggered within the components/com_content/views/article/view.html.php file. You can see the code below that triggers each event below:

// Process the content plugins.
$results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset));

$item->event = new stdClass();
$results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results));

$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));

$results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));

Testing each plugin event

In our plugin's PHP file, helloworld.php, we added the following functions to test each of the above triggers:

public function onContentPrepare($context, &$row, &$params, $limitstart)
    echo "<div>OnContentPrepare</div>";

public function onContentAfterTitle($context, &$row, &$params, $limitstart)
    return "<div>OnContentAfterTitle</div>";

public function onContentBeforeDisplay($context, &$row, &$params, $limitstart)
    return "<div>OnContentBeforeDisplay</div>";

public function onContentAfterDisplay($context, &$row, &$params, $limitstart)
    return "<div>OnContentAfterDisplay</div>";

Timing Plugin Events

triggers-and-eventsAs you can see in the screenshot to the right, each plugin event is triggered at different points of the article setup. For example, some events are triggered before the article is displayed, some triggered during, and some ran after.


The OnContentPrepare event is triggered before the article is printed to the screen. If you wanted to modify the content in some way, this would be the hook to use. While this plugin modifies the article, the other events add content to the article.


The OnContentAfterTitle event allows you to add content to the article after the title is printed but before the introtext is displayed.


The onContentBeforeDisplay event is very similar to OnContentAfter Title, but it runs after it.


After the content of an article has been displayed, you can run OnContentAfterDisplay to add information to the end of the article.

Joomla Community Google+ Hangout #3

June 3rd, 2014

Thank you @RustyJoomla for letting me speak on the Joomla Community Google+ Hangout!

Click here to watch!

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

n/a Points
2014-09-09 11:44 am

Very useful!


2012-12-31 2:21 pm
Thank you. I managed to set a session variable at the start of my plugin and then change it after first run of the onContentPrepare function. It's done the job- not very elegant, but it works. Thanks for your time all the same.
9,968 Points
2012-12-31 10:40 am
Hello Netamity,

I think we know what you're trying to accomplish, but unfortunately we don't have a clear answer for you right at this moment. If you could please provide us with an example URL of where this is happening for you, or at the very least a screen shot showing what's going on this could help us troubleshoot this faster for you.

I believe you might need to modify the actual onContentPrepare function, so that it can keep track of how many times it has run on a page, and limit itself to only once. Once we get back an example from you we should be able to test this out a bit and let you know what we come up with.

- Jacob
2012-12-30 6:57 pm
Thanks for this info.
I'm trying to get content output before all titles and content and just once (even if it's a category blog) but by using the onContentPrepare, it still runs the function for each item, so the echo in my function outputs for the number of articles I am displaying (which is fine for single articles, but no good for blogs). Is there any way I can get my plug-in content output just once above everything else in the content view?

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

4 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!