Bolt CMS中的三层子菜单

时间:2015-04-06 17:08:06

标签: twig bolt-cms

我一直试图在Bolt中实现三层子菜单。我希望菜单只显示顶层,除非在菜单中选择了该菜单,此时,我只想显示第二层。如果选择了第二层中的菜单选项,我希望仅显示该选择的子菜单。到目前为止,我已经尝试过这个:

{% for item in menu %}

<li class="{% if item|current %}active{% endif %}">
    <a href=" {{ item.link }}" {% if item.title is defined %}title='{{ item.title|escape }}'{% endif %}
       class='{% if item.class is defined %}{{item.class}}{% endif %}'>
         {% if item.submenu is defined and item|current %} <i class='fa fa-lg fa-caret-down'></i> {% elseif item.submenu is defined and not item|current %}<i class='fa fa-lg fa-caret-right'></i>{% endif %}
        {{item.label}}
    </a>
</li>
{% if item.submenu is defined  and item|current %}
    <ul class="nav nav-level2">
          {% for item in item.submenu %}
            <li {% if item|current %}class='active' {% endif %}>
                <a href="{{ item.link }}" {% if item.title is defined %}title='{{ item.title|escape }}'{% endif %}>
                    {{item.label}}
                </a>
            </li>
            {% if item.submenu is defined%}
                {% if item|current %}
                  <ul class='nav nav-level3'>
                    {% for item in item.submenu %}
                    <li class='{% if item|current %}active{% endif %}'>
                        <a href="{{ item.link }}" {% if item.title is defined %}title='{{ item.title|escape }}'{% endif %}>
                            {{item.label}}
                        </a>
                    </li>
                    {% endfor %}
                  </ul>
              {% endif %}
            {% endif %}
        {% endfor %}
    </ul>
{% endif %}

{%endfor%}

config.yml中的我的菜单结构为:

_sample menu:
  - label: First Section
    path: First_Section_Path
  - label: Second Section
    path: second_section_path
    submenu:
      -label: Second tier 
       path: second_tier_path
       submenu:
         -label: Third tier
         -path: third_tier_path
  - label: Third Section
    path: third_section_path

有更好的方法吗?或者我只是遗漏了一些明显的东西?

提前感谢您的帮助。

0 个答案:

没有答案