<p>Try:</p>

<pre><code>if craft.entries.section('aboutus').lightswitch_field('1')|length
</code></pre>

<p>If you want to check if it is "off" use:</p>

<pre><code>if craft.entries.section('aboutus').lightswitch_field('not 1')|length
</code></pre>

CC BY-SA 3.0
2016-03-23T09:32:55.513Z
This sadly does not work. Both returns true. Any other idea?
Jonathan Schiffner
CC BY-SA 3.0
2016-03-23T18:09:23.850Z
Updated my answer.
Brad Bell
CC BY-SA 3.0
2016-03-22T17:17:48.370Z
2016-03-23T18:09:14.537Z
2016-03-23T18:09:14.537Z
Brad Bell
<p>For a menu I have to check if a <code>lightswitch</code> field is on or not. The menu is in an extra header file. I've tried:</p>

<pre><code>{% if craft.entries.section('aboutus').lightswitch_field %}style="display: none;"{% else %} ... {% endif %}
</code></pre>

<p>but this always jumps into the <code>else</code> part.</p>

<templating><entries><lightswitch>
Check in header file if lightswitch field is on
# Check in header file if lightswitch field is on

(Asked by: username_0 on 2016-03-22)

For a menu I have to check if a lightswitch field is on or not. The menu is in an extra header file. I've tried:
{% if craft.entries.section('aboutus').lightswitch_field %}style="display: none;"{% else %} ... {% endif %}

but this always jumps into the else part.

**Tags:** templating, entries, lightswitch

---

## 1 answers

### Answer by username_1 on 2016-03-22. Score: 1 | Accepted answer

Try:
if craft.entries.section('aboutus').lightswitch_field('1')|length

If you want to check if it is "off" use:
if craft.entries.section('aboutus').lightswitch_field('not 1')|length

> **Comments:**
> **username_0**: This sadly does not work. Both returns true. Any other idea?  
> **username_1**: Updated my answer.  

---

