[英]Prestashop add css to a module
I am creating a module in prestashop 1.4, say blocktest
我正在 prestashop 1.4 中创建一个模块,比如
blocktest
modules/blocktest/blocktest.php:模块/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:模块/blocktest/blocktest.css:
* { background-color: red; }
In admin > preferences > performances > smarty
, i have set cache to no
, and force compile to yes
.在
admin > preferences > performances > smarty
中,我已将缓存设置为no
,并强制编译为yes
。 In admin > preferences > performances > smarty
, cache is set to no
.在
admin > preferences > performances > smarty
中,缓存设置为no
。
Existing modules uses the same css inclusion: Tools::addCSS($this->_path.'blocktest.css', 'all');
现有模块使用相同的 css 包含:
Tools::addCSS($this->_path.'blocktest.css', 'all');
, but the css file is in <themeName>/css/modules/<moduleName>/<moduleName>.css
. ,但 css 文件位于
<themeName>/css/modules/<moduleName>/<moduleName>.css
中。 Which is wierd, because $this->_path points to the module folder: modules/<moduleName>/
.这很奇怪,因为 $this->_path 指向模块文件夹:
modules/<moduleName>/
。
But anyway, I tried to put my css file in <themeName>/css/modules/blocktest/blocktest.css
, that doesn't work.但无论如何,我试图将我的 css 文件放在
<themeName>/css/modules/blocktest/blocktest.css
中,但这不起作用。 Maybe i am missing something也许我错过了什么
Did you remember about registering a hook for the header during module's installation?您还记得在模块安装期间为 header 注册一个挂钩吗?
function install() {
if (!parent::install())
return false;
if (!$this->registerHook('header'))
return false;
return true;
}
Without it you will have to use "transplant module" function from Admin > Modules > Positions, to do this.没有它,您将不得不使用“管理”>“模块”>“职位”中的“移植模块”function 来执行此操作。 Always check with tools like Firebug to verify whether your files are there.
始终使用 Firebug 等工具检查您的文件是否存在。
Also, I think there is something missing, can you supply us with the full code of your module?另外,我认为缺少一些东西,您能否向我们提供您模块的完整代码? Please, provide us with a Prestashop version that you use as well.
请向我们提供您也使用的 Prestashop 版本。
Other solution:其他解决方案:
$this->context->controller->addCSS(($this->_path).'style.css', 'all');
$this->context->controller->addJs(($this->_path).'script.js', 'all');
Greetings,问候,
source info:来源信息:
http://www.prestashop.com/forums/topic/235476-solucionadoerror-en-mi-1ra-web-warning-function-addcss-is-deprecated-in/ http://www.prestashop.com/forums/topic/235476-solucionadoerror-en-mi-1ra-web-warning-function-addcss-is-deprecated-in/
Which is wierd, because $this->_path points to the module folder: modules//
这很奇怪,因为 $this->_path 指向模块文件夹:modules//
yes it is (weird), but... in the addCSS function, it is overriden with (module) themes css folder是的,它是(奇怪的),但是......在 addCSS function 中,它被(模块)主题 css 文件夹覆盖
public static function addCSS($css_uri, $css_media_type = 'all')
{
global $css_files;
...
$css_uri = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.