是否可以创建第二个通用/菜单以用于不同的布局?

时间:2019-05-31 09:05:01

标签: twig opencart-3

如果可以创建自定义通用页面,我需要了解什么。我需要创建一个自定义菜单,因为默认渲染代码不适合我的需要。而且我找不到在树枝环境中爆炸{{menu}}的解决方案。

我尝试使用以下代码在catalog / controller / menucustom.php中创建:

<?php
class ControllerCommonMenucustom extends Controller {
public function index() {
    $this->load->language('common/menucustom');

    // Menu
    $this->load->model('catalog/category');
    $this->load->model('catalog/product');
    $data['categories'] = array();
    $categories = $this->model_catalog_category->getCategories(0);

    foreach ($categories as $category) {
        if ($category['top']) {
            // Level 2
            $children_data = array();

            $children = $this->model_catalog_category->getCategories($category['category_id']);

            foreach ($children as $child) {
                $filter_data = array(
                    'filter_category_id'  => $child['category_id'],
                    'filter_sub_category' => true
                );

                $children_data[] = array(
                    'name'  => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
                    'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
                );
            }

            // Level 1
            $data['categories'][] = array(
                'name'     => $category['name'],
                'children' => $children_data,
                'column'   => $category['column'] ? $category['column'] : 1,
                'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
        }
    }

    return $this->load->view('common/menucustom', $data);
}

}

接下来我已经在其中为menucustom控制器创建了一个相对视图 目录/视图/主题/主题/模板/常见,带有以下代码:

 {% if categories %}
<div class="container">
  <nav id="menu" class="navbar">

    <div class="collapse navbar-collapse navbar-ex1-collapse">
      <ul class="nav navbar-nav">
        {% for category in categories %}
        {% if category.children %}
        <li class="dropdown"><a href="{{ category.href }}" class="dropdown-toggle" data-toggle="dropdown">{{ category.name }}</a>
          <div class="dropdown-menu">

            {% for children in category.children|batch(category.children|length / category.column|round(1, 'ceil')) %}
              <ul class="list-unstyled">
                {% for child in children %}
                <li><a class="dropdown-item" href="{{ child.href }}">{{ child.name }}</a></li>
                {% endfor %}
              </ul>
              {% endfor %}

            <a class="nav-item see-all" href="{{ category.href }}" >{{ text_all }} {{ category.name }}</a> </div>
        </li>
        {% else %}
        <li><a class="nav-item" href="{{ category.href }}">{{ category.name }}</a></li>
        {% endif %}
        {% endfor %}
      </ul>
    </div>
  </nav>
</div>
{% endif %}

之后,我尝试渲染在主题编辑器->标头中调用{{menucustom}}的视图。

什么都没发生。显然,如果我创建了一个模块,则可以访问控制器的输出数据,但是“常见”没有。有没有办法实现我的目标?谢谢

0 个答案:

没有答案