0

I would like to assign a specific template for a certain category, I have tried with this code in a plugin system but without success (this code does not include the condition for the category I will do it afterwards.

<?php
defined('_JEXEC') or die;

class templateSwitcherCategory extends JPlugin
{
    
    public function __construct(&$subject, $config)
    {
        // Calling the parent Constructor
        parent::__construct($subject, $config);

        // Do some extra initialisation in this constructor if required
    }

    
    public function onAfterInitialise()
    {
        $app      = JFactory::getApplication();
        $app->setTemplate('protostar', null);       
        return true;
    }       
}
?>
2
  • Welcome to JSE. Please take our tour. Can you tell us how your code fails? (is there an error? is a value not populated/printed as expected?) Offering the results of your diagnostic checks will invariably help volunteers to understand the issue and help you faster. Oct 12, 2020 at 22:28
  • First, plugin class has to follow a naming convention like this: Plg<PluginGroup><PluginName>. See documentation docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla.
    – Sharky
    Oct 13, 2020 at 5:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.