<p>Based on <a href="https://craftcms.com/docs/lightswitch-fields" rel="nofollow noreferrer">https://craftcms.com/docs/lightswitch-fields</a> and <a href="https://craftcms.stackexchange.com/a/352/5134">https://craftcms.stackexchange.com/a/352/5134</a>:</p>

<pre><code>{% if entry.lightswitchFieldHandle %}
    {% if currentUser %}
        Display entry that only logged users can see
    {% endif %}
{% else %}
    Display entry that anyone can see
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-08-12T22:16:22.520Z
How can I display the entry?
JustinTheeDude
CC BY-SA 3.0
2016-08-09T21:01:19.273Z
2016-08-09T21:01:19.273Z
2017-04-13T12:51:00.303Z
Michael
<p>So I want to hide certain items if a user is not logged into the website. I already have a custom lightswitch field on each of the items but I'm not sure on how to write the code for it. Can anyone help?</p>

<lightswitch>
Hiding specific items from public
# Hiding specific items from public

(Asked by: username_0 on 2016-08-09)

So I want to hide certain items if a user is not logged into the website. I already have a custom lightswitch field on each of the items but I'm not sure on how to write the code for it. Can anyone help?

**Tags:** lightswitch

---

## 1 answers

### Answer by username_1 on 2016-08-09. Score: 3

Based on https://craftcms.com/docs/lightswitch-fields and https://craftcms.stackexchange.com/a/352/5134:
{% if entry.lightswitchFieldHandle %}
    {% if currentUser %}
        Display entry that only logged users can see
    {% endif %}
{% else %}
    Display entry that anyone can see
{% endif %}

> **Comments:**
> **username_0**: How can I display the entry?  

---

