How can I change the template set in back-end with a custom plugin?
I was different solutions suggesting using
$doc= JFactory::getDocument();
$doc->setTemplate("my_tempalte_name");
which did not work.
How can I change the template set in back-end with a custom plugin?
I was different solutions suggesting using
$doc= JFactory::getDocument();
$doc->setTemplate("my_tempalte_name");
which did not work.
In Joomla 3.2. + you can make use of the JApplicationSite::setTemplate
method.
You need to put this in a system plugin which triggers on onAfterInitialise
.
public function onAfterInitialise()
{
$app = JFactory::getApplication();
// We want to change the template just on the FE
if ($app instanceof JApplicationSite)
{
$template = $app->getTemplate(); //use just debugging
var_dump($template); //use just debugging
// Set the new template and style params
$app->setTemplate('protostar', null);
$template = $app->getTemplate(); //use just debugging
var_dump($template); //use just debugging
}
}
The signature JApplicationSite::setTemplate
of is:
/**
* Overrides the default template that would be used
*
* @param string $template The template name
* @param mixed $styleParams The template style parameters
*
* @return void
*
* @since 3.2
*/
public function setTemplate($template, $styleParams = null)