2013-08-24 35 views
2

正在prestashop 1.5中开发一个模块。我正在使用displayAdminProductsExtra挂钩在admin选项卡中显示tpl文件。当我在tpl中包含我的jquery代码时,它工作正常。但是当我尝试将其作为新文件并包含其不工作时。到目前为止,我尝试下面的方法..如何在prestashop 1.5中添加JS模块?

使用displayBackOfficeHeader注册一个钩子,并呼吁这样的..

public function hookdisplayBackOfficeHeader($params) 
{ 
    $this->context->controller->addJS(($this->_path).'abc.js'); 
} 

,我试着将它添加在displayAdminProductsExtra也是这样..

$this->context->controller->addJS(_MODULE_DIR_.$this->module->name.'/views/js/abc.js'); //first tried.. 
$this->context->controller->addJS(($this->_path).'abc.js','all'); //second tried this.. 

我试图用这样的getContent ..

public function getContent() 
{ 
    $this->_html= '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"> 
     <script src="../modules/abc/abc.js" type="text/javascript" ></script>'; 
    return $this->_html; 
} 

但这些方法没有添加我的js文件。不知道我在哪里犯错。任何帮助将不胜感激。

+0

[看看本作详细的解答](http://www.vipulhadiya.com/prestashop-module-development-tutorial-creating-front-and-admin-view-in-prestashop-module /) –

+0

下次再说。 –

回答

4

当您创建Prestashop模块时,您必须添加函数hookHeader,并在其中添加将js添加到页面中的行。

那就需要像这样:

public function hookHeader ($ params) 
{ 
     $ this-> controller-> addJS (($ this-> _path). 'abc.js'); 
} 

在另一方面,看着blockcategories.php文件模块blockcategories的代码中,我们看到以下内容:

public function displayForm() 
{ 
... 
} 

此功能以与使用其他模块相同的方式为模块配置创建一个页面。也许这是一个更简单的选择,但开发速度更快。

问候

相关问题