onContentPrepare run once - Joomla! Forum - community, help and support
i creating content plug-in of want content appear @ top of component content no matter whether it's single article, category blog, list ,etc.
i want plug-in contents appear above everything- above category title in category blog example. event runs oncontentprepare. using 'echo' instead of 'return' in function, have been able text printed screen, function runs each content item repeating.
can use oncontentprepare echo content above else once no matter how many items there are, or there better event use content appearing @ top?
oncontentaftertitle/oncontentbeforedisplay, etc display content each content item , in wrong spot.
if had wish, there'd event insert plug-in content after page title, before first item- if know how this, better!
any guidance appreciated- how echo once???
edit: managed fudge setting session variable in function means of checking whether function had been run. it's not elegant, works. if has better way of doing please let me know.
i want plug-in contents appear above everything- above category title in category blog example. event runs oncontentprepare. using 'echo' instead of 'return' in function, have been able text printed screen, function runs each content item repeating.
can use oncontentprepare echo content above else once no matter how many items there are, or there better event use content appearing @ top?
oncontentaftertitle/oncontentbeforedisplay, etc display content each content item , in wrong spot.
if had wish, there'd event insert plug-in content after page title, before first item- if know how this, better!
any guidance appreciated- how echo once???
code: select all
public function oncontentprepare($context, &$row, &$params, $page=0)
{
echo '<h1>hey</h1>' ;
}edit: managed fudge setting session variable in function means of checking whether function had been run. it's not elegant, works. if has better way of doing please let me know.
i agree, wanted more elegant that, , looked everywhere , found alot of inadequate answers. far have this::
code: select all
defined( '_jexec' ) or die( 'restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgcontentmyplugin extends jplugin{
function pluginmyplugin( &$subject, $params ){
parent::__construct( $subject, $params);
}
//set static variable
public static $addonce=false;
function onafterrender(){
self::$addonce=false;
}
function onbeforecompilehead(){
if(self::$addonce==true){
//do once if needed
addscript('myscript.js');
}
}
function oncontentprepare($context,&$article,&$params,$page=0){
if(testforsomething==true){
//do every time occurs;
mypluginfunction();
//and add header once
self::$addonce=true;
}
return true;
}
}
Comments
Post a Comment