Come impostare un modello a livello di programmazione utilizzando un plugin
Domanda
Come posso cambiare il modello impostato in back-end con un plugin personalizzato?
Sono state diverse soluzioni che suggeriscono usando
$doc= JFactory::getDocument();
$doc->setTemplate("my_tempalte_name");
.
che non ha funzionato.
Soluzione
in Joomla 3.2.+ È possibile utilizzare il metodo JApplicationSite::setTemplate
.
È necessario inserirlo in un plug-in di sistema che si attiva su 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
}
}
.
La firma JApplicationSite::setTemplate
di è:
/**
* 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)
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow