Answers.Body: <p>You can use <code>entry.level</code> in a conditional:</p>
  
  <pre><code>{% set entries = craft.entries.section('spb') %}
  {% nav entry in entries %}
  
      {% set liTagAttributes = entry.level == 1 ? 'class="uk-parent" data-uk-dropdown' : 'class="uk-child"' %}
  
      &lt;li {{ liTagAttributes|raw }}&gt;
          &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
          {% ifchildren %}
              ...
          {% endifchildren %}
      &lt;/li&gt;
  
  {% endnav %}
  </code></pre>
  
  <p>I set a intermediate var to keep the template code clean. If you don't have many levels in your structure, you could also consider to not use the <code>nav</code> tag at all and nest your navigation levels using <code>hasDescendents</code> and <code>getDescendents(1)</code> (see the example code I <a href="https://craftcms.stackexchange.com/a/1847/125">posted here</a>).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-18T09:27:14.100Z
Answers.Text: Very useful tip! Thank you. By the way, you don't need to use double quotes in `{% set liTagAttributes = entry.level == 1 ? 'class=uk-parent data-uk-dropdown' : 'class=uk-child' %}`
Answers.UserDisplayName: Stanislav Ulver
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-18T09:31:54.460Z
Answers.Text: Errrm, this wasn't for the Twig code but to make it return valid HTML for setting the CSS class, @Stanislav.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-18T09:37:11.270Z
Answers.Text: Sure, but if you leave them it returns two times double quotes `""...""`
Answers.UserDisplayName: Stanislav Ulver
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-18T09:37:13.340Z
Answers.Text: Sorry, you were right. HTML5 does indeed allow you to NOT wrap attribute values in quotes.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-18T09:43:49.200Z
Answers.Text: @Stanislav forgot to add the `raw` filter to the output. This makes Twig to not escape the code and you end up with single quotes. I definitely don't recommend to use attribute value without quotes at all.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-17T18:32:26.867Z
Answers.LastActivityDate: 2014-12-18T09:41:36.710Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: carlcs
Body: <p>Doing my first site with Craft and UiKit framework I encountered a small problem with dropdown menu. Here is my code:</p>
  
  <pre><code>&lt;ul&gt;
    {% set entries = craft.entries.section('spb') %}
    {% nav entry in entries %}
    &lt;li class="uk-parent" data-uk-dropdown&gt;
      &lt;a {% if craft.request.getPath() == entry.uri %} class="active" {% endif %} href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
      {% ifchildren %}
      &lt;div class="uk-dropdown"&gt;
        &lt;ul class="uk-nav uk-nav-dropdown"&gt;
          {% children %}
        &lt;/ul&gt;
      &lt;/div&gt;
      {% endifchildren %}
    &lt;/li&gt;
    {% endnav %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>The point is that my child element looks exactly like parent because it takes its structure. But I don't need neither "class" nor "data-uk-dropdown" element...</p>
  
  <pre><code>&lt;li class="uk-parent" data-uk-dropdown=""&gt;&lt;a href="#"&gt;...&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Is there any workaround? Thanks.</p>
  
Tags: <navigation><drop-down>
Title: Navigation drop-down problem
ThreadText: # Navigation drop-down problem
  
  (Asked by: username_0 on 2014-12-17)
  
  Doing my first site with Craft and UiKit framework I encountered a small problem with dropdown menu. Here is my code:
  
  ```
  <ul>
    {% set entries = craft.entries.section('spb') %}
    {% nav entry in entries %}
    <li class="uk-parent" data-uk-dropdown>
      <a {% if craft.request.getPath() == entry.uri %} class="active" {% endif %} href="{{ entry.url }}">{{ entry.title }}</a>
      {% ifchildren %}
      <div class="uk-dropdown">
        <ul class="uk-nav uk-nav-dropdown">
          {% children %}
        </ul>
      </div>
      {% endifchildren %}
    </li>
    {% endnav %}
  </ul>
  
  ```
  
  The point is that my child element looks exactly like parent because it takes its structure. But I don't need neither "class" nor "data-uk-dropdown" element...
  
  ```
  <li class="uk-parent" data-uk-dropdown=""><a href="#">...</a></li>
  
  ```
  
  Is there any workaround? Thanks.
  
  **Tags:** navigation, drop-down
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-17. Score: 2 | Accepted answer
  
  You can use `entry.level` in a conditional:
  
  ```
  {% set entries = craft.entries.section('spb') %}
  {% nav entry in entries %}
  
      {% set liTagAttributes = entry.level == 1 ? 'class="uk-parent" data-uk-dropdown' : 'class="uk-child"' %}
  
      <li {{ liTagAttributes|raw }}>
          <a href="{{ entry.url }}">{{ entry.title }}</a>
          {% ifchildren %}
              ...
          {% endifchildren %}
      </li>
  
  {% endnav %}
  
  ```
  
  I set a intermediate var to keep the template code clean. If you don't have many levels in your structure, you could also consider to not use the `nav` tag at all and nest your navigation levels using `hasDescendents` and `getDescendents(1)` (see the example code I [posted here](https://craftcms.stackexchange.com/a/1847/125)).
  
  > **Comments:**
  > **username_0**: Very useful tip! Thank you. By the way, you don't need to use double quotes in `{% set liTagAttributes = entry.level == 1 ? 'class=uk-parent data-uk-dropdown' : 'class=uk-child' %}`  
  > **username_1**: Errrm, this wasn't for the Twig code but to make it return valid HTML for setting the CSS class, @username_0.  
  > **username_0**: Sure, but if you leave them it returns two times double quotes `""...""`  
  > **username_1**: Sorry, you were right. HTML5 does indeed allow you to NOT wrap attribute values in quotes.  
  > **username_1**: @username_0 forgot to add the `raw` filter to the output. This makes Twig to not escape the code and you end up with single quotes. I definitely don't recommend to use attribute value without quotes at all.  
  
  ---
  
  