0

I created a custom Joomla plugin and I want to display my custom data on content in category blog. I use oncontentprepare event for display data. But in category blog only show all data on first article. My sample code this is:

   public function oncontentprepare ($context , &$article , &$params , $page=0)
    {

   $attribs = json_decode($article->attribs);
   echo $attribs->customData;


  }

when echo my data only show on first article in category blog. I want display data by using my plugin and without use template overwrite or regular expression.
How can do it? it's possible? thank you

1 Answer 1

3

Yes, it is very possible to do what you want. Joomla provides a series of triggers for content rendering which allows a developer to append content. You have three trigger which are relevant to your use case:

onContentAfterTitle
onContentBeforeDisplay
onContentAfterDisplay

Each of these methods reference a point in the content rendering cycle you can insert HTML to be incorporated into the final rendering. We'll use onContentBeforeDisplay as an example.

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

    // You must verify you are appending to correct component view
    if (!in_array($context, array('com_content.category')))
    {
        return true;
    }

    $html = "<span>My Appended Content!</span>"
    return $html;
}

Simple as that, but be sure to verify you are in the correct component view before appending. You can also insert into multiple components and component views if needed.

Hope this helps!

Content Plugin Events

4
  • Thank you dear Brian Bolli it's work now how can display my data before article title? I want display data before articles title
    – saber
    Apr 24, 2015 at 8:19
  • you should be able to use OnContentBeforeDisplay method for this. Apr 24, 2015 at 13:22
  • I use OnContentBeforeDisplay but display my text after article title I want display data before title
    – saber
    Apr 24, 2015 at 14:44
  • If you want to display before the title you will have to create a custom a template override and can a) move the onBeforeContentDisplay trigger to above the title or b) create a custom content event trigger and place before any rendering is done inside your template override file. Apr 24, 2015 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.