我是 Prestashop 1.7 的新手。我需要覆盖一个CSS。我已经在 Prestashop 附带的 custom.css 上编写了 css 代码。当我刷新网站时,自定义 CSS 不适用。没有链接 rel 指向该文件。
我想问一下如何调用custom.css。有一个 stylesheets.tpl 但我不确定要写什么代码。
最佳答案
您可以使用位于 frontController 中的 setMedia() 函数在最新的 PrestaShop 中添加自定义 CSS 和 JS,如下所示:
路径:mainDir/classes/controller/FrontController.php
public function setMedia()
{
$this->registerStylesheet('theme-main', '/assets/css/theme.css', ['media' => 'all', 'priority' => 50]);
$this->registerStylesheet('theme-custom', '/assets/css/custom.css', ['media' => 'all', 'priority' => 1000]);
if ($this->context->language->is_rtl) {
$this->registerStylesheet('theme-rtl', '/assets/css/rtl.css', ['media' => 'all', 'priority' => 900]);
}
$this->registerJavascript('corejs', '/themes/core.js', ['position' => 'bottom', 'priority' => 0]);
$this->registerJavascript('theme-main', '/assets/js/theme.js', ['position' => 'bottom', 'priority' => 50]);
$this->registerJavascript('theme-custom', '/assets/js/custom.js', ['position' => 'bottom', 'priority' => 1000]);
$assets = $this->context->shop->theme->getPageSpecificAssets($this->php_self);
if (!empty($assets)) {
foreach ($assets['css'] as $css) {
$this->registerStylesheet($css['id'], $css['path'], $css);
}
foreach ($assets['js'] as $js) {
$this->registerJavascript($js['id'], $js['path'], $js);
}
}
// Execute Hook FrontController SetMedia
Hook::exec('actionFrontControllerSetMedia', array());
return true;
}
关于css - 如何在 Prestashop 1.7 中调用 custom.css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43756398/