Opencart获取当前的layout_id

时间:2013-07-09 05:22:55

标签: layout get opencart

我创建了一个自定义布局,我计划仅为那些自定义布局指定页面隐藏产品。

有没有办法获得当前的布局ID?

例如,假设我的自定义layout_id为10,我打算使用下面的一些循环来隐藏/显示产品

if (current_layout_id != 10) {
  // Display products
}else {
  // Hide Products
}

1 个答案:

答案 0 :(得分:2)

查找当前显示的模块页面的布局ID

if (isset($this->request->get['route'])) { 
        $route = $this->request->get['route']; 
    } else { 
        $route = 'common/home'; 
    }
    $layout_id = 0;
    if (substr($route, 0, 16) == 'product/category' && isset($this->request->get['path'])) {
        $path = explode('_', (string)$this->request->get['path']);
        $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
    }
    if (substr($route, 0, 16) == 'product/product' && isset($this->request->get['product_id'])) {
        $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
    }
    if (substr($route, 0, 16) == 'product/information' && isset($this->request->get['information_id'])) {
        $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
    }
    if (!$layout_id) { $layout_id = $this->model_design_layout->getLayout($route); }
    if (!$layout_id) { $layout_id = $this->config->get('config_layout_id'); }

布局ID发现结束