0

互联网上对 OpenCart 的所有帮助都在*.tpl文件上......但是 OpenCart 现在已经更新,所以我面临的基本问题是我想在顶部菜单中添加一个信息页面“关于我们”。没有我可以更改的 HTML 视图,所以我有一个.twig文件,它只让类别显示在顶部菜单中,如下所示:

{% if categories %}
<div class="container">
  <nav id="menu" class="navbar">
    <div class="navbar-header"><span id="category" class="visible-xs">{{ text_category }}</span>
      <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars">    </i></button>
    </div>

    <div class="collapse navbar-collapse navbar-ex1-collapse">
      <ul class="nav navbar-nav">
        {% for category in categories %}
        {% if category.children %}


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

        </li>

        {% else %}
        <li><a href="{{ category.href }}">{{ category.name }}</a></li>

       {% endif %}
        {% endfor %}

       <li><a href="{{ information.href }}">{{ information.href }}</a></li>

    </ul>

      </div>
    <ul class="nav navbar-nav">
    <li><a href="{{ localhost/ghazi/upload/about_us }}">About US</a></li>

    </ul>
    </nav>
    </div>
{% endif %} 

控制器是 menu.php 如下:

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

        // Menu
        $this->load->model('catalog/category');

        $this->load->model('catalog/product');
        $this->load->model('catalog/information');
        $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/menu', $data);
        }
        }

我只想在顶部菜单中显示关于我们的页面

4

1 回答 1

0

由于编辑控制器以显示页面实际上与编辑模板类似,因为您正在调整代码,我觉得最简单的方法是在twig文件上硬编码 URL。假设您要在现有菜单的末尾添加菜单项,您可以尝试以下代码:

{% if categories %}
<div class="container">
  <nav id="menu" class="navbar">
    <div class="navbar-header"><span id="category" class="visible-xs">{{ text_category }}</span>
      <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
    </div>
    <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">
            <div class="dropdown-inner"> {% for children in category.children|batch(category.children|length / category.column|round(1, 'ceil')) %}
              <ul class="list-unstyled">
                {% for child in children %}
                <li><a href="{{ child.href }}">{{ child.name }}</a></li>
                {% endfor %}
              </ul>
              {% endfor %}</div>
            <a href="{{ category.href }}" class="see-all">{{ text_all }} {{ category.name }}</a> </div>
        </li>
        {% else %}
        <li><a href="{{ category.href }}">{{ category.name }}</a></li>
        {% endif %}
        {% endfor %}
        <li><a href="http://storeURL/index.php?route=information/information&information_id=4">About Us</a></li>  
      </ul>
    </div>
  </nav>
</div>
{% endif %} 

请确认信息页面的ID确实是“4”,并更改storeURL为您的商店的ID。

我们可以更进一步,将 storeURL 包含在控制器文件中,然后在菜单中引用它,但我认为这是没有真正好处的额外工作,特别是如果您只想在顶部菜单中显示一个信息页面。

于 2017-08-24T05:48:59.687 回答