覆盖Prestashop setMedia函数将js和css文件放在底部

时间:2016-07-11 11:59:03

标签: smarty prestashop

我熟知FrontController覆盖

class FrontController extends FrontControllerCore {

   public function setMedia()
    {
      parent::setMedia();   
      $this->addJS(array(
        _THEME_JS_DIR_.'adds.js'
       ));  
    }
}

这个wokrks按预期但有一个问题 - >将这个新的js / css文件添加到包含文件列表的顶部,如下所示:

<script type="text/javascript" src="/js/adds.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="/js/jquery/plugins/jquery.easing.js"></script>
<script type="text/javascript" src="/js/tools.js"></script>
<script type="text/javascript" src="/themes/default-bootstrap/js/global.js"></script>

这很糟糕,因为我的剧本落在了jquery的剧本之上......

如何制作这样

<script type="text/javascript" src="/js/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="/js/jquery/plugins/jquery.easing.js"></script>
<script type="text/javascript" src="/js/tools.js"></script>
<script type="text/javascript" src="/themes/default-bootstrap/js/global.js?version=2"></script>
<script type="text/javascript" src="/js/adds.js"></script>

2 个答案:

答案 0 :(得分:0)

我使用hookHeader函数创建了一个简单的自定义模块(50行),如下所示。像魅力一样工作!

public function hookHeader($params)
     {
         $this->context->controller->addCSS($this->_path.'css/adds.css', 'all');
         $this->context->controller->addJS($this->_path.'js/adds.js', 'all');

     }

答案 1 :(得分:0)

我在 addJS()之前使用 addJquery()来添加jQuery,例如:

public function hookBackOfficeHeader()
{
    $this->context->controller->addJquery();
    $this->context->controller->addJS(Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/my.js');
}

http://doc.prestashop.com/display/PS16/Using+jQuery+and+jQueryUI