Opencart为类别添加额外的tpl布局

Stu*_*art 4 opencart

我想在Opencart 1.5.4中设置其他页面和类别布局.

我已进入一个阶段,如果我将新类别的路径输入地址栏,新模板会显示我想要的,但我似乎无法在OC中注册该路由更改.

如果我在.htaccess文件中指定了更改,则新模板会按预期加载,但我不是这个问题的正确答案(尽管它有效).

添加.htaccess(我确定不是正确的方法)

RewriteRule ^skis$ index.php?route=product/categories&path=1  [L,QSA]
Run Code Online (Sandbox Code Playgroud)

我创建了两个新文件

/catalog/view/theme/default/template/product/categories.tpl
/catalog/controller/product/categories.php
Run Code Online (Sandbox Code Playgroud)

在/catalog/controller/product/categories.php中,我更改了内容以反映新的tpl文件;

class Controllerproductcategories extends Controller {
Run Code Online (Sandbox Code Playgroud)

.

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/categories.tpl')) {
 $this->template = $this->config->get('config_template') . '/template/product/categories.tpl';
} else {
 $this->template = 'default/template/product/categories.tpl';
}
Run Code Online (Sandbox Code Playgroud)

所以总结一下

  1. 如果我在.htaccess文件中指定重写,则加载布局,如果我不加载则不加载.
  2. 我在OC中添加了一个新的布局,并根据该类别选择了它在此输入图像描述在此输入图像描述

任何人都有任何想法,我可能会试图让这个正常工作?我有大量模板可以为产品,类别和信息页面创建,因此我们希望正确地执行此操作.

Tx提前

斯图

Stu*_*art 5

我最终选择了这种方法..可能会帮助别人.

if ($this->data['heading_title'] == "Skis") {

    $this->template = $this->config->get('config_template') . '/template/product/categories.tpl';

} elseif ($this->data['heading_title'] == "Softgoods") {

    $this->template = $this->config->get('config_template') . '/template/product/category.tpl';

} elseif ($this->data['heading_title'] == "Outlet Store") {

    $this->template = $this->config->get('config_template') . '/template/product/category.tpl';

} else {

    $this->template = $this->config->get('config_template') . '/template/product/category.tpl';

}
Run Code Online (Sandbox Code Playgroud)

  • 很好,虽然你可能会更好地使用switch语句而不是所有那些if else's (3认同)