プラグインを使用してプログラムでテンプレートを設定する方法
質問
カスタムプラグインでバックエンドで設定したテンプレートを変更する方法は?
私は
を使用していることを示唆しているさまざまな解決策でした$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