كيفية تعيين قالب برمجيا باستخدام مكون إضافي
سؤال
كيف يمكنني تغيير القالب الذي تم تعيينه في النهاية الخلفية باستخدام مكون إضافي مخصص?
كنت حلولا مختلفة أقترح استخدام
$doc= JFactory::getDocument();
$doc->setTemplate("my_tempalte_name");
التي لم تنجح.
المحلول
في جملة 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