<p>I want to display different code blocks if a category level is 1 or 2 or 3 – on a category page, but finding this hard to do, 
if I'm on an entry page I can use:</p>

<pre><code>{% if entry.level == 1 %}
</code></pre>

<p>how can I use the equivalent but for a category on a category page?
Thanks</p>

CC BY-SA 4.0
2019-11-28T11:13:00.597Z
Did you tried this: https://docs.craftcms.com/v3/dev/element-queries/category-queries.html#parameters ?
Romain P.
CC BY-SA 4.0
2019-11-29T12:24:42.660Z
Thank you, I need to update this post as my code must have been wrong as – the simple line:   
```{% if category.level < 2 %}``` does work!
user2569
<categories>
Conditionally test for a category level
# Conditionally test for a category level

(Asked by: username_0 on 2019-11-27)

I want to display different code blocks if a category level is 1 or 2 or 3 – on a category page, but finding this hard to do, 
if I'm on an entry page I can use:
{% if entry.level == 1 %}

how can I use the equivalent but for a category on a category page?
Thanks

**Tags:** categories

> **Comments:**
> **username_1**: Did you tried this: https://docs.craftcms.com/v3/dev/element-queries/category-queries.html#parameters ?  
> **username_0**: Thank you, I need to update this post as my code must have been wrong as – the simple line:    ```{% if category.level < 2 %}``` does work!  

---

## 0 answers

