Templates 根据产品id加载产品模板';

Templates 根据产品id加载产品模板';,templates,opencart,Templates,Opencart,我有大约20个产品需要加载特定的产品模板,而其他所有产品都加载默认模板。这是我到目前为止的代码。我不知道如何合并多个产品id。任何帮助都将不胜感激 if ($this->request->get['product_id'] == 200000864) { if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/customproduct.tp

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

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


你想要这个或其他东西

硬编码这真的不是个好主意。您最好使用一些使用代码格式的东西。谢谢您的建议,但我不想为扩展支付50美元。没有办法硬编码正确吗?我有点困惑产品ID应该放在哪里。我道歉。我对PHP不是很熟悉。产品id在“case:”中,自定义模板将在该case语句中,如果您不理解,请告诉我
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));
            }
 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));
    }