1

I like to create a plugin which should override the template only when no template is set on the Menu

Now I struggle with the lifecycle phases of the plugin and the framework.

I need to set the template in the call back method "onAfterInitialise" but at this time the "active menu" is not available.

The active menu becomes available during the call back method "onAfterRoute", but there get my "setTemplate" call ignored, because the template seems to be already set by the system because the menu has a template set.

public function onAfterInitialise() {
    $menu = JFactory::getApplication()->getMenu();
    // this is null
    $active =   $menu->getActive();
     var_dump($active);
    // otherwiese I could easily get the template style id 
    // and verify if it is the default one ....
}

public function onAfterRoute() {
    if ( JFactory::getApplication()->isClient( 'site' ) ) {
        // get ignored by the system
        $this->_setTemplateStyle(10); 
    }
}

// set template via id
protected function _setTemplateStyle( $style ) {
    $style  =   JCckDatabase::loadObject( 'SELECT id,template,params,home FROM #__template_styles WHERE id = '.(int)$style );
    // var_dump($style);

    if ( is_object( $style ) ) {
        JFactory::getApplication()->setTemplate( $style->template, $style->params );
    }       
}

Any idea?

megloff
  • 1,400
  • 4
  • 27
  • 44

0 Answers0