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.

Like this Article?

Login to comment.

Your Opinion Matters

... but we need to know what you're thinking!

I'm Brad Markle, your friendly Community Support technician, and I wrote the article you're looking at now. I like to think it's perfect, but I'm sure you have some suggestions. Please, let me know what they are!

Feedback
Your Email Address
Because we'd like to talk with you!

Latest Questions

If you need some help, submit your question to our Community!
We guarantee a response within 60 minutes (8am - 9pm EST, Monday - Friday)
Ask a Question!
Recent Questions
  1. how to change may site name in joomla 3.0?
  2. Cpanel license is expired
  3. How do I provide a truly secure FTP site for my client to upload files with sensitive data (PHI - Personal Health Information, as referred to by HIPAA)?

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!