Answers.Body: <p>You can filter <code>elements</code> based on their hierarchy level with the <code>level</code> attribute</p>
  
  <pre><code>{% for category in categories.level(1).all() %} 
  </code></pre>
  
  <p>Will only show top tier categories</p>
  
  <pre><code>{% for category in categories.level(2).all() %}
  </code></pre>
  
  <p>only all the first tier children of all first tier categories (so tier 2) and so on.</p>
  
  <p><em>Additional note</em> </p>
  
  <p>You can also search for descendants elements</p>
  
  <pre><code>element.getDescendants(1) //&lt;-- include the level based on the parents level
  </code></pre>
  
  <p>With the parameter  <code>1</code> it is the same as</p>
  
  <pre><code>element.getChildren()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-26T18:56:26.387Z
Answers.LastActivityDate: 2018-05-26T18:56:26.387Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm looking to only display the top level parent categories on my Template, but unfortunately, everything I try seems to error out and still display all of the children categories as well.</p>
  
  <p>My current code looks like the following:</p>
  
  <pre><code>  {% set categories = craft.categories.group('discounts') %}
          {% for category in categories.all() %}
  </code></pre>
  
Tags: <categories>
Title: Only display the first tier of categories
ThreadText: # Only display the first tier of categories
  
  (Asked by: username_0 on 2018-05-26)
  
  I'm looking to only display the top level parent categories on my Template, but unfortunately, everything I try seems to error out and still display all of the children categories as well.
  
  My current code looks like the following:
  
  ```
    {% set categories = craft.categories.group('discounts') %}
          {% for category in categories.all() %}
  
  ```
  
  **Tags:** categories
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-26. Score: 2 | Accepted answer
  
  You can filter `elements` based on their hierarchy level with the `level` attribute
  
  ```
  {% for category in categories.level(1).all() %} 
  
  ```
  
  Will only show top tier categories
  
  ```
  {% for category in categories.level(2).all() %}
  
  ```
  
  only all the first tier children of all first tier categories (so tier 2) and so on.
  
  *Additional note*
  
  You can also search for descendants elements
  
  ```
  element.getDescendants(1) //<-- include the level based on the parents level
  
  ```
  
  With the parameter `1` it is the same as
  
  ```
  element.getChildren()
  
  ```
  
  
  ---
  
  