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.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

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

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

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: support@InMotionHosting.com
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!