Summary


I got small problem with changing the template  via plugin,

in j2.5 I just use JFactory::getApplication()->setTemplate('template_name'); that I call in onAfterDispatch event

in j3.2 it have no any result, because JApplicationSite::setTemplate do not overwrite the template stored in config:

// Store the template and its params to the config
$this->set('theme', $template->template);
$this->set('themeParams', $template->params);
Opened On:
19 Nov 2013, 7:41 by Fedik Zinchuk
Closed On:
27 Jul 2014, 12:28
Status:
Not a bug

Filed Under

  • CMS Libraries
  • No Platform Implications

Responses

Posted on 21 Nov 2013, 4:50 by Valentin Despa

Did you try using it on onAfterInitialise()?

Does this help: http://stackoverflow.com/questions/20049266/how-to-set-a-template-programmatically-using-a-plugin
Posted on 21 Nov 2013, 5:20 by Fedik Zinchuk

it will work ,

but question/bug is that setTemplate() do not work as expected in some cases
Posted on 21 Nov 2013, 6:14 by Valentin Despa

What I wanted to point out is that setTemplate does actually work, it does not work when called at onAfterDispatch.
Posted on 25 Feb 2014, 14:42 by Hannes Papenberg

This is broken indeed. :-)
Posted on 5 May 2014, 12:14 by bernard saulme

* Same issues for Joomla 3.3
* Some complements:
Into a component; both lines do not have effect:
 JFactory::getApplication()-->setTemplate('protostar', null); // No effect
 JApplicationSite::setTemplate('protostar'); // No effect
Into a system plugin, into the onAfterInitialise() event:
 JFactory::getApplication()-->setTemplate('protostar', null); // Is working
 JApplicationSite::setTemplate('protostar'); // No effect
 
Posted on 27 Jul 2014, 12:28 by Nicholas Dionysopoulos

Hello and thank you for contributing to Joomla!. What you describe is the expected behaviour of Joomla!. As you correctly figured out the correct way to do that is call JFactory::getApplication()-->setTemplate('protostar', null); in onAfterInitialise. A component cannot change the template, that's correct and expected behaviour. The component is called long after Joomla! has decided which template to use.
Posted on 16 Feb 2015, 8:10 by Nick Weavers

Hi Nicholas,

In fact the component can change the template. See my Joomla issue here which actually shows what the problem is and how to workaround it. 

JApplicationSite::setTemplate() stores the template name you give it into the JApplicationCms::template property, but in Joomla 3.3 the render method in the same class uses the getter JApplicationWeb::get() to retrieve a property called theme, which the getter retrieves from its the JApplicationWeb::config property that is a registry object.

So between 2.5 and 3.3 I see there has been a change in the terminology used for template and a change in the way this information is stored and retrieved that hasn't been applied to JApplicationSite::setTemplate().

If I replace JFactory::getApplication('')->setTemplate() in my components constructor with JFactory::getApplication()->set('theme', '') it works, so this is my workaround.

I believe JApplicationSite::setTemplate() needs to be updated to store the template name it is passed in the correct place for Joomla 3. The term template seems to have been changed to theme and is now saved within a registry object stored in JApplicationWeb::config. The setter JApplicationWeb::set() should do this   

 

 

 

 

 
Posted on 16 Feb 2015, 9:44 by Nick Weavers

Hi Nicholas,

In fact the component can change the template. See my Joomla issue here which actually shows what the problem is and how to workaround it. 

The problem arrived in Joomla 3.3.

JApplicationSite::setTemplate() stores the template name you give it into the JApplicationCms::template property, but in Joomla 3.3 the render method in the same class uses the getter JApplicationWeb::get() to retrieve a property called theme, which the getter retrieves from its the JApplicationWeb::config property that is a registry object.

So between 2.5 and 3.3 I see there has been a change in the terminology used for template and a change in the way this information is stored and retrieved that hasn't been applied to JApplicationSite::setTemplate(). 

If I replace JFactory::getApplication('')->setTemplate() in my components constructor with JFactory::getApplication()->set('theme', '') it works, so this is my workaround.

I believe JApplicationSite::setTemplate() needs to be updated to store the template name it is passed in the correct place for Joomla 3. The term template seems to have been changed to theme and is now saved within a registry object stored in JApplicationWeb::config. The setter JApplicationWeb::set() should do this in JApplicationSite::setTemplate.

Stop press:

I raised this as an issue this morning and it was fixed within 3 hours (fix on github). Way to go!