我正在 prestashop 1.4 中创建一个模块,比如说 blocktest
modules/blocktest/blocktest.php:
...
public function hookLeftColumn($params)
{
global $smarty;
$smarty->assign(array(
'test' => 'test'
));
return $this->display(__FILE__, 'blocktest.tpl');
}
public function hookHeader()
{
Tools::addCSS($this->_path.'blocktest.css', 'all');
}
modules/blocktest/blocktest.css:
* { background-color: red; }
问题:
我的css不包含在内。我尝试了什么:
在admin > preferences > performances > smarty
, 我已将缓存设置为 no
, 并强制编译为 yes
.在 admin > preferences > performances > smarty
, 缓存设置为 no
.
现有模块使用相同的 css 包含:Tools::addCSS($this->_path.'blocktest.css', 'all');
, 但 css 文件在 <themeName>/css/modules/<moduleName>/<moduleName>.css
中.这很奇怪,因为 $this->_path 指向模块文件夹:modules/<moduleName>/
.
但无论如何,我试图将我的 css 文件放在 <themeName>/css/modules/blocktest/blocktest.css
中,那是行不通的。也许我遗漏了什么
最佳答案
您还记得在模块安装期间为 header 注册一个钩子(Hook)吗?
function install() {
if (!parent::install())
return false;
if (!$this->registerHook('header'))
return false;
return true;
}
如果没有它,您将不得不使用 Admin > Modules > Positions 中的“移植模块”功能来执行此操作。始终使用 Firebug 等工具检查以验证您的文件是否存在。
此外,我认为还缺少一些东西,您能否向我们提供您的模块的完整代码?请向我们提供您也使用的 Prestashop 版本。
关于php - Prestashop 将 css 添加到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7027427/