Как установить шаблон программно с помощью плагина
Вопрос
Как я могу изменить шаблон, установленный в серверной части, с помощью пользовательского плагина?
У меня были разные решения, предлагающие использовать
$doc= JFactory::getDocument();
$doc->setTemplate("my_tempalte_name");
что не сработало.
Решение
В Joomla 3.2.+ вы можете воспользоваться JApplicationSite::setTemplate
метод.
Вам нужно поместить это в системный плагин, который запускается при 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
}
}
Подпись JApplicationSite::setTemplate
из является:
/**
* 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)
Не связан с StackOverflow