【问题标题】:Opencart add additional tpl layout for a categoryOpencart 为一个类别添加额外的 tpl 布局
【发布时间】:2012-11-29 23:24:07
【问题描述】:

我正在尝试在 Opencart 1.5.4 中设置其他页面和类别布局。

我已经到了一个阶段,如果我在地址栏中输入新类别的路线,新模板会按我的意愿显示,但我似乎无法在 OC 中注册该路线更改。

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

.htaccess 的补充(我确定方法不正确)

RewriteRule ^skis$ index.php?route=product/categories&path=1  [L,QSA]

我创建了两个新文件

/catalog/view/theme/default/template/product/categories.tpl
/catalog/controller/product/categories.php

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

class Controllerproductcategories extends Controller {

.

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';
}

总结一下

  1. 如果我在布局加载的 .htaccess 文件中指定重写,否则不会。
  2. 我在 OC 中添加了一个新布局,并针对类别 选择了它

任何人有任何想法我可以尝试让它正常工作吗?我有大量模板要为产品、类别和信息页面创建,因此希望能正确执行此操作。

提前发送

学习

【问题讨论】:

    标签: opencart


    【解决方案1】:

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

    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';
    
    }
    

    【讨论】:

    • 很好,虽然你可能最好使用 switch 语句而不是所有那些 if else 的
    【解决方案2】:

    据我所知,您正在尝试对每个单独的模板进行硬编码,但实际上并不能按照您为类别使用布局选择的方式工作。布局旨在安排页面上的内容,而不是指定模板

    我实际上已经创建了您想要实现的商业版本,可以在here 找到。它允许您创建模板并将其分配给一个或多个页面。它适用于产品、类别、制造商和信息页面。它还允许您为整个类别或制造商下的产品指定模板

    【讨论】:

    • 所以布局是用于 OC 模块,而不是模板文件的覆盖。啊,真糟糕。感谢插件上的链接,但我会坚持使用 .htaccess 方法,我对插件的信心越来越差,升级,缺乏测试,尤其是大型产品集等。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多