<p>This line:</p>

<pre><code>{% set hideMenu = craft.entries.section('mysection').showMainNavigation('not 1').one() %} 
</code></pre>

<p>will return the first entry that it can find in the section 'mysection' that has <code>showMainNavigation</code> off. So as soon as you disable it for one entry, <code>hideMenu</code> will 'return' true, whichever page you're on.</p>

<p>So to fix this, if <code>mainEntry</code> is your current entry, then replace the line by:</p>

<pre><code>{% set hideMenu = mainEntry.showMainNavigation %} 
</code></pre>

CC BY-SA 4.0
2019-11-19T19:36:10.300Z
Wow, I was really overthinking this! mainEntry is not the current entry but I used your example to fix this. {% set showMenu = entry.showMainNavigation %} then {% if not showMenu%}hide navigation{% else %}show navigation.
user9494
CC BY-SA 4.0
2019-11-19T18:31:36.363Z
2019-11-19T18:31:36.363Z
Seb
<p>I am looking to hide the main navigation for entries that have the lightswitch 'showMainNavigation' disabled. The problem I am facing is when I disable for one entry, the navigation is hidden for all entries. Here is a sample of the code:</p>

<pre><code>{% set mainEntry = craft.entries.slug(craft.app.request.getSegment(1)).one() %}
{% set menuLogo = mainEntry.menuLogo %}
{% set hideMenu = craft.entries.section('mysection').showMainNavigation('not 1').one() %} 

{% if hideMenu %}
&lt;nav class="navbar navbar-expand-lg main-menu"&gt;
    &lt;div class="standard-wrapper"&gt;
        {% if menuLogo|length %}
        &lt;div class="navbar-brand logo logo-white visible"&gt;&lt;a href="#"&gt;&lt;img src="{{siteUrl}}{{menuLogo.one().getUrl()}}"/&gt;&lt;/a&gt;&lt;/div&gt;
        {% endif %}
    &lt;/div&gt;
&lt;/nav&gt;

{% else %}

&lt;nav class="navbar navbar-expand-lg main-menu"&gt;
    &lt;div class="standard-wrapper"&gt;
        {% if menuLogo|length %}
        &lt;div class="navbar-brand logo logo-white visible"&gt;&lt;a href="#"&gt;&lt;img src="{{siteUrl}}{{menuLogo.one().getUrl()}}"/&gt;&lt;/a&gt;&lt;/div&gt;
        {% endif %}
        &lt;button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" onclick="myFunction(this)"&gt;
            &lt;span class="navbar-toggler-icon"&gt;
            &lt;div class="bar1"&gt;&lt;/div&gt;
            &lt;div class="bar2"&gt;&lt;/div&gt;
            &lt;div class="bar3"&gt;&lt;/div&gt;&lt;/span&gt;
        &lt;/button&gt;

        &lt;div class="collapse navbar-collapse float-right menu" id="navbarSupportedContent"&gt;
            &lt;ul class="navbar-nav mr-auto no-list-style"&gt;
                &lt;li class="nav-item active"&gt;list item 1&lt;/li&gt;
                &lt;li class="nav-item active"&gt;list item 2&lt;/li&gt;
            &lt;/ul&gt;
         &lt;/div&gt;
     &lt;/div&gt;
&lt;/nav&gt;
{% endif %}
</code></pre>

<craft3><lightswitch>
Hide navigation from one entry but not others
# Hide navigation from one entry but not others

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

I am looking to hide the main navigation for entries that have the lightswitch 'showMainNavigation' disabled. The problem I am facing is when I disable for one entry, the navigation is hidden for all entries. Here is a sample of the code:
{% set mainEntry = craft.entries.slug(craft.app.request.getSegment(1)).one() %}
{% set menuLogo = mainEntry.menuLogo %}
{% set hideMenu = craft.entries.section('mysection').showMainNavigation('not 1').one() %} 

{% if hideMenu %}

    
        {% if menuLogo|length %}
        
        {% endif %}
    


{% else %}


    
        {% if menuLogo|length %}
        
        {% endif %}
        
            
            
            
            
        

        
            
                list item 1
                list item 2
            
         
     

{% endif %}

**Tags:** craft3, lightswitch


---

## 1 answers

### Answer by username_1 on 2019-11-19. Score: 2 | Accepted answer

This line:
{% set hideMenu = craft.entries.section('mysection').showMainNavigation('not 1').one() %} 

will return the first entry that it can find in the section 'mysection' that has showMainNavigation off. So as soon as you disable it for one entry, hideMenu will 'return' true, whichever page you're on.
So to fix this, if mainEntry is your current entry, then replace the line by:
{% set hideMenu = mainEntry.showMainNavigation %}

> **Comments:**
> **username_0**: Wow, I was really overthinking this! mainEntry is not the current entry but I used your example to fix this. {% set showMenu = entry.showMainNavigation %} then {% if not showMenu%}hide navigation{% else %}show navigation.  

---

