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.

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;
  • 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. – mickmackusa Oct 12 '20 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 '20 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.