プラグインを使用してプログラムでテンプレートを設定する方法

StackOverflow https://stackoverflow.com//questions/20049266

  •  26-12-2019
  •  | 
  •  

質問

カスタムプラグインでバックエンドで設定したテンプレートを変更する方法は?

私は

を使用していることを示唆しているさまざまな解決策でした
$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)
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top