Opencart 2中如何创建单独的模板输出品类?
How to create a separate template to output the category in Opencart 2?
OpenCart 2 上的商店中有几类商品,需要彼此进行结构和设计。如何实施?访问了创建控制器和模板输出的选项,但不起作用...
在 Opencart 2 中,body
已将 class
关联到您正在查看的页面,例如,如果您在一个类别中,body
class
应该是:
<body class="product-category-20">
你可以这样使用它:
body.product-category-20 {
background-color: red;
}
另一个类别;
body.product-category-21 {
background-color: green;
}
要为每个类别分配不同的模块,您可以添加新布局,然后在编辑或创建新类别时从设计选项卡中select此布局。
已解决。
有人能派上用场吗
文件中\catalog\controller\product\category.php
替换代码:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/category.tpl', $data));
}
为此:
$template = 'category.tpl';
if ($category_id == 72) { $template = 'category-72.tpl'; }
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/'.$template)) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/'.$template, $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/'.$template, $data));
}
请输入您的类别 ID,而不是 72。
在此处创建我们类别的模板:
\catalog\view\theme\NAME_THEME\template\product\category-72.tpl
然后转到 Admin -> Modules -> Modifiers 并更新缓存。完成。
OpenCart 2 上的商店中有几类商品,需要彼此进行结构和设计。如何实施?访问了创建控制器和模板输出的选项,但不起作用...
在 Opencart 2 中,body
已将 class
关联到您正在查看的页面,例如,如果您在一个类别中,body
class
应该是:
<body class="product-category-20">
你可以这样使用它:
body.product-category-20 {
background-color: red;
}
另一个类别;
body.product-category-21 {
background-color: green;
}
要为每个类别分配不同的模块,您可以添加新布局,然后在编辑或创建新类别时从设计选项卡中select此布局。
已解决。 有人能派上用场吗
文件中\catalog\controller\product\category.php
替换代码:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/category.tpl', $data));
}
为此:
$template = 'category.tpl';
if ($category_id == 72) { $template = 'category-72.tpl'; }
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/'.$template)) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/'.$template, $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/'.$template, $data));
}
请输入您的类别 ID,而不是 72。
在此处创建我们类别的模板:
\catalog\view\theme\NAME_THEME\template\product\category-72.tpl
然后转到 Admin -> Modules -> Modifiers 并更新缓存。完成。