Here's a little tipbit I added to Fabrik today to allow your custom components to access Joomla's content plugins

[EDIT] The original post is at the bottom now, however I have just found a cleaner way of doing what I originaly posted:
$text = JHTML::_('content.prepare', $text );
[/EDIT]


In you view (e.g. components/com_mycomponent/views/myview/view.html.php) Your display() method usually ends with this: parent::display();

This loads the template and echo's it out, however it doesn't run Joomla's content plugins through your template output.

So instead replace that with this:

$o = new stdClass();$o->text = $this->loadTemplate();
JPluginHelper::importPlugin('content');
$dispatcher = &
JDispatcher::getInstance();
$results = $dispatcher->trigger('onPrepareContent', array (&$o, array(), 0));
echo $o->text;

Views: 3336

Replies to This Discussion

Ah, the infinite joy of using Joomla! :)
Nice.
nice- I've never looked or knew about the JModuleHelper or thought of using JObject rather than stdClass()

Personally for forward compatibility I'd replace the global $mainframe with :

$app =& JFactory::getApplication();
Dang it!... I was doing this the other day and wasted much time getting it to work properly... and the code was sitting here all along. Thanks for sharing! This is a pretty common thing I need in my components.

And Nicholas... I appreciate your post as well.... ha ha "the infinite joy". It's like I tell my clients when they ask "can you do X in Joomla"... you can do ANYTHING...given time and money. :D

James
just to say that I have edited this post with a much shorter way of achieving the same out put
I noticed that some plugin actually expect option=com_content for them to process onPrepareContent properly, so you might actually want to "fool" them by callin JRequet::setVar and restoring the correct values after the trigger.
ah ok thanks - good to know :)

Cheers
Rob
Thanks, I was looking for this just now. Your post came up first in Google, I didn't even realize I was browsing the ATAAW :) I gotta say, I just love the JHTML classes, they're so powerful! Cheers Babs
Cool! saved me tons of time!

RSS

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service