<p>craft.request is useful for setting an &quot;active&quot; class based on URL segments without slug.
In your template you can set a slug in twig and then you can run if statement to check what the segment is. Check below example for that.</p>
<pre><code>&lt;ul&gt;
    {% set slug = craft.app.request.getSegment(1) %}                        
    {% for entry in entries %}
        {% set destination = entry.linkDestination.one() %}
        &lt;li {% if slug == destination.slug or (destination.slug == 'home' and slug == null) %} class=&quot;active&quot; {% endif %}&gt;
            &lt;a href=&quot;{{ destination.url }}&quot;&gt;&lt;span&gt;{{ entry.linkText }}&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
    {% endfor %}   
&lt;/ul&gt;
</code></pre>

CC BY-SA 4.0
2020-12-30T07:55:00.020Z
2020-12-30T07:55:00.020Z
ZealousWeb
<p>Is their is any way to set active class to a page when slug is not define?</p>

<craft3>
How to set Home page menu as active when slug is not defined in admin panel?
# How to set Home page menu as active when slug is not defined in admin panel?

(Asked by: username_0 on 2020-12-30)

Is their is any way to set active class to a page when slug is not define?

**Tags:** craft3


---

## 1 answers

### Answer by username_1 on 2020-12-30. Score: 1 | Accepted answer

craft.request is useful for setting an "active" class based on URL segments without slug.
In your template you can set a slug in twig and then you can run if statement to check what the segment is. Check below example for that.

    {% set slug = craft.app.request.getSegment(1) %}                        
    {% for entry in entries %}
        {% set destination = entry.linkDestination.one() %}
        
            {{ entry.linkText }}
        
    {% endfor %}


---

