كيفية تعيين قالب برمجيا باستخدام مكون إضافي

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

  •  26-12-2019
  •  | 
  •  

سؤال

كيف يمكنني تغيير القالب الذي تم تعيينه في النهاية الخلفية باستخدام مكون إضافي مخصص?

كنت حلولا مختلفة أقترح استخدام

$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)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top