2013-08-24 34 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() 
{ 
... 
} 

此功能以與使用其他模塊相同的方式爲模塊配置創建一個頁面。也許這是一個更簡單的選擇,但開發速度更快。

問候

相關問題