Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-30T07:55:00.020Z
Answers.LastActivityDate: 2020-12-30T07:55:00.020Z
Answers.UserDisplayName: ZealousWeb
Body: <p>Is their is any way to set active class to a page when slug is not define?</p>
  
Tags: <craft3>
Title: How to set Home page menu as active when slug is not defined in admin panel?
ThreadText: # 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.
  
  ```
  <ul>
      {% set slug = craft.app.request.getSegment(1) %}                        
      {% for entry in entries %}
          {% set destination = entry.linkDestination.one() %}
          <li {% if slug == destination.slug or (destination.slug == 'home' and slug == null) %} class="active" {% endif %}>
              <a href="{{ destination.url }}"><span>{{ entry.linkText }}</span></a>
          </li>
      {% endfor %}   
  </ul>
  
  ```
  
  
  ---
  
  