Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

Is it possible to build something like this with a structure and the {% nav %} tag?

     <ul class="nav navbar-nav">
       <li class="dropdown">
         <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>
         <ul class="dropdown-menu">
           <li>
               <div class="yamm-content">
                  <div class="row"> 
                    ...
           </li>
         </ul>
       </li>
     </ul>

This is my code for now:

{% set entries = craft.entries.section('pagina') %}
   <ul class="nav navbar-nav">
      {% nav entry in entries %}
         <li {{ activeClass(entry.slug) }} {% if entry.hasDescendants() %}class="dropdown yamm-fw"{% endif %}>     
            <a href="#" {% if entry.hasDescendants() %}dropdown-toggle{% endif %}" {% if entry.hasDescendants() %}data-toggle="dropdown"{% endif %}>{{ entry.title }}</a>

            {% ifchildren %}
               <ul class="dropdown-menu">
                  {% children %}
               </ul>
            {% endifchildren %}
         </li>
      {% endnav %}
   </ul>

The problem is, i need custom html inside the children

share|improve this question

2 Answers 2

You'll want to make use of the level property of your entry...

{% if entry.level == 1 %}
    <!-- Top Level Links -->
{% else %}
    <!-- Child Links -->
{% endif %}
share|improve this answer

For more control over nav output I like to use a recursive macro:

{% macro recursive_nav(entries, depth) %}
{% import _self as self %}
  <ul>
    {% for entry in entries %}
      <li>
        {{ entry }}
        {% if entry.hasDescendents() %}
          {{ self.recursive_nav(entry.children, depth+1) }}
        {% endif %}
      </li>
  </ul>
{% endmacro %}

{% set entries = craft.entries.section('pagina') %}
{{ recursive_nav(entries, 1) }}

You can test depth in the macro, and customize your output accordingly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.