首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据产品id加载产品模板

根据产品id加载产品模板
EN

Stack Overflow用户
提问于 2015-04-03 23:19:03
回答 1查看 179关注 0票数 0

我大约有20个左右的产品需要加载特定的产品模板,而所有其他产品都加载默认模板。这是我到目前为止拥有的代码。我想不出如何合并多个产品id。任何帮助都将不胜感激。

代码语言:javascript
复制
if ($this->request->get['product_id'] == 200000864) {
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/customproduct.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl';
    } else {
        $this->template = '/template/product/customproduct.tpl';
    }
} else {
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/product/product.tpl';
    } else {
        $this->template = '/template/product/customproduct.tpl';
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-04-04 16:20:42

Opencart 2.0

从…

代码语言:javascript
复制
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
                $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/product.tpl', $data));
            } else {
                $this->response->setOutput($this->load->view('default/template/product/product.tpl', $data));
            }

代码语言:javascript
复制
 switch ($this->request->get['product_id']) {
    case 1:
      $this->response->setOutput($this->load->view('default/template/product/product1.tpl', $data));
        break;
    case 2:
        $this->response->setOutput($this->load->view('default/template/product/product2.tpl', $data));
        break;

      //...
      //...
      //...
    case 200000864:
        $this->response->setOutput($this->load->view('default/template/product/product200000864.tpl', $data));
        break;
    default:
        $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/product.tpl', $data));
    } 

你想要这个还是别的什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29434957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档