correct way to use custom 'content' plugin on all content and components

169 views
Skip to first unread message

TheCellarRoom

unread,
Jun 14, 2013, 9:24:05 AM6/14/13
to joomla-de...@googlegroups.com
I have a plugin that inserts code snippets on to com_content items but need this to be extended to all other components

I am aware from the joomla docs something such as this:

$dispatcher =& JDispatcher::getInstance();
$item->content = $text;
JPluginHelper::importPlugin('plgContentshortcodes'); 
$dispatcher->trigger('onContentPrepare', array ($item->text, 0));

or this: 

$dispatcher = JDispatcher::getInstance();
$item->text = your_text_area_item;  
$item->params = clone($params);
JPluginHelper::importPlugin('content'); 
$dispatcher->trigger('onPrepareContent', array (& $item, & $item->params, 0))

 should work, but can't seem to make any headway on this 

Does anyone have a working example or guidance please?


ta

Allon Moritz

unread,
Jun 14, 2013, 9:28:45 AM6/14/13
to joomla-de...@googlegroups.com
Perhaps you can use some of the system plugin events which are called on every page load http://docs.joomla.org/Plugin/Events/System


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

TheCellarRoom

unread,
Jun 14, 2013, 9:31:39 AM6/14/13
to joomla-de...@googlegroups.com
Should probably add i'm working on version 3.1.1 

Matt Thomas

unread,
Jun 14, 2013, 9:51:44 AM6/14/13
to Joomla! General Development
I've had similar situations in the past and have needed to change it from being a content to system plugin.


That said, based on your code examples, it looks like you are trying to trigger the plugin event in a component, is that correct?





Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



On Fri, Jun 14, 2013 at 9:31 AM, TheCellarRoom <chelse...@gmail.com> wrote:
Should probably add i'm working on version 3.1.1 

TheCellarRoom

unread,
Jun 14, 2013, 10:06:44 AM6/14/13
to joomla-de...@googlegroups.com
it is yes, although it needs to run in all components.

Allon Moritz

unread,
Jun 14, 2013, 10:10:37 AM6/14/13
to joomla-de...@googlegroups.com
If you create a system plugin add the following code in the after render function, otherwise it will break extensions which are using raw(ajax) or other non html requests

if (JFactory::getDocument()->getType() != 'html') {
return;
}


Franz

unread,
Jun 14, 2013, 10:29:05 AM6/14/13
to joomla-de...@googlegroups.com
Possibly a little OT, but to avoid headaches I'd suggest that "running in all components" is an impossible task. How could Joomla know which fields of any component is a text field?
Now, if your question is, "how do I run content plugins on a given text", the answer is quite easy:

$text = JHtml::_('content.prepare', $text);

Matt Thomas

unread,
Jun 14, 2013, 10:29:22 AM6/14/13
to Joomla! General Development
I think the confusion is that not all components will necessarily trigger the content plugin events.

The suggestion is to change your plugin to be a system type, so that it is always triggered by the CMS regardless of the component.

In my example, I was previously using the onPrepareContent event to alter $article->title, but had to change it to a broader system plugin using onAfterRender so that I could use it outside of com_content and modify the entire page buffer.

In other words, as far as I know, you can't reliably use custom 'content' plugin on all content and components.

Best,

Matt Thomas
Founder betweenbrain™
Lead Developer Construct Template Development Framework
Phone: 203.632.9322
Twitter: @betweenbrain
Githubhttps://github.com/betweenbrain

Composed and delivered courtesy of Nexus 7.

TheCellarRoom

unread,
Jun 14, 2013, 10:35:25 AM6/14/13
to joomla-de...@googlegroups.com
yes I think this is the issue, I've moved over to a system plugin. but not working as yet.

essentially the plugin is looking for shortcodes {footer-text}, {contact-details} and replacing with content stored in the custom component, edited in the backend. these 'shortcodes' can appear in any component part of the site as the client sees fit.


thanks to all so far.

Franz

unread,
Jun 19, 2013, 11:53:36 AM6/19/13
to joomla-de...@googlegroups.com
Thanks to Matt who was better than me at understanding and explaining the source of confusion.


Il giorno venerdì 14 giugno 2013 16:29:22 UTC+2, betweenbrain ha scritto:
I think the confusion is that not all components will necessarily trigger the content plugin events.

The suggestion is to change your plugin to be a system type, so that it is always triggered by the CMS regardless of the component.

In my example, I was previously using the onPrepareContent event to alter $article->title, but had to change it to a broader system plugin using onAfterRender so that I could use it outside of com_content and modify the entire page buffer.

In other words, as far as I know, you can't reliably use custom 'content' plugin on all content and components.

Matt Thomas

unread,
Jun 19, 2013, 12:06:15 PM6/19/13
to Joomla! General Development
You're welcome. I'm glad it helped!

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



--

joomla ace not

unread,
Jun 27, 2013, 10:02:04 AM6/27/13
to joomla-de...@googlegroups.com
i have been searching for something like this for a while. The plugin i have created needs to include some external javascript and also insert javascript into the head or body. Does anybody know how that can be achieved? 

Many thanks in advance

Matt Thomas

unread,
Jun 27, 2013, 10:14:13 AM6/27/13
to Joomla! General Development
You will need to use http://docs.joomla.org/JDocument/addScript and http://docs.joomla.org/JDocument/addScriptDeclaration to add the script and sript declaration.

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



--

Franz

unread,
Jun 27, 2013, 10:49:36 AM6/27/13
to joomla-de...@googlegroups.com
Please do not cross post on duplicate threads. This thread is closed, keep the discussion in the other one your opened.
Reply all
Reply to author
Forward
0 new messages