Joomla 2.5 content plugin variables

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.

In our last article, we covered the various events at which content plugins can be triggered. For example, we looked at both onContentPrepare and onContentAfterTitle. You may have noticed that when each plugin is triggered, it is passed the following variables:

  • com_content.article
  • &$item
  • &$this->params
  • $offset
$results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset));

In this content plugin tutorial, we will look at each of these variables more closey and examine what they include.

When looking at Joomla’s Pagebreak plugin’s php file, you can see an example of how the functions are written to handle these variables. For example, to access com_content.article, the $context variable would be used.

public function onContentPrepare($context, &$row, &$params, $page = 0)

com_content.article / $context

There’s not much to look at with com_content.article, it helps define the context of what is triggering the function. For example, if $context = com_content.article, you know that you’re code is being called within an article.

&$item / &$row

$row is an object and contains the content of the article and other information about it. For example, it will include the id of the article, the title and alias, and much more. You can view all of the items in the $row object by printing it to the screen using the following code:

public function onContentPrepare($context, &$row, &$params, $page = 0)
{
    echo "<pre>"; print_r($row); echo "</pre>";
}

As you can see in the screenshot below, there is a ton of information about the article stored in this object!

print_r_row

&$this->params / &$params

The params object contains obviously the paramters of the article. For example, the following are all considered article paramters:

  • show_title
  • show_intro
  • show_hits

To see all of the values within the $params object, you can print the variable to the screen using the following code:

public function onContentPrepare($context, &$row, &$params, $page = 0)
{
    echo "<pre>"; print_r($params); echo "</pre>";
}

$offset / $page = 0

If you’re using Page Breaks to split up an article, the $page variable will tell you which page you’re on. By default, $page will be 0. When somone is on the second page of the article, $page will have a value of 1, and so on.

Comments

It looks like this article doesn't have any comments yet - you can be the first. If you have any comments or questions, start the conversation!

Was this article helpful? Let us know!