Run content plugins on JDocument type RAW (ie temp. replace JDocument with a different type)


/ Published in: PHP
Save to your folder(s)

Say you want to run content plugins on JDocumentRAW content (like in a component that returns JSON data). Some methods in JDocumentHTML like "addCustomTag" will cause the app to fail on JDocumentRAW doc types which don't have this method. Thus you need to temporarily replace it to trick the content plugins...


Copy this code and paste it in your HTML
  1. $document =& JFactory::getDocument();
  2. $oldDoc = clone( $document );
  3. $document = JDocument::getInstance('html');
  4.  
  5. JPluginHelper::importPlugin('content');
  6. $article = new JObject();
  7. $article->text = $lesson->rendered;
  8. $dum = array();
  9. $dispatcher->trigger( 'onPrepareContent', array( &$article, &$dum, 0 ) );
  10. $lesson->rendered = $article->text;
  11.  
  12. $document = $oldDoc;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.