<p>If you want to restrict an entire template, something like the following should work.</p>

<pre><code>{% set authorized = false %}
{% if currentUser %}
    {% if currentUser.isInGroup('employee') %}
        {% set authorized = true %}
    {% endif %}
{% endif %}

{% if not authorized %}
    {% redirect 401 %}
{% endif %}

{# display template #}
</code></pre>

<p>Note: You can redirect anywhere with the <code>redirect</code> tag. I just used 401 as an example. </p>

<p>If you want to designate whether specific entries are viewable then you might want to set a custom field — something like a 'lightbox' field with the handle 'public' for example.</p>

<pre><code>{% set authorized = false %}
{% if currentUser %}
    {% if currentUser.isInGroup('employee') %}
        {% set authorized = true %}
    {% endif %}
{% endif %}

{% if authorized %}
    {# show non-public positions #}
    {% set positions = craft.entries.section('jobPostings').public('0') %}
    &lt;h2&gt;In-house Job Openings&lt;/h2&gt;
    &lt;ul&gt;
        {% for position in positions %}
            &lt;li&gt;&lt;a href="{{ position.url }}"&gt;{{ position.title }}&lt;/a&gt;&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endif %}

{# show public positions #}
&lt;h2&gt;Public Job Openings&lt;/h2&gt;
{% set positions = craft.entries.section('jobPostings').public('1') %}
&lt;ul&gt;
    {% for position in positions %}
        &lt;li&gt;&lt;a href="{{ position.url }}"&gt;{{ position.title }}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>Then on the detail page (if there is a detail page), do the same:</p>

<pre><code>{% set authorized = false %}
{% if currentUser %}
    {% if currentUser.isInGroup('employee') %}
        {% set authorized = true %}
    {% endif %}
{% endif %}

{% if not entry.public and not authorized %}
    {% redirect 401 %}
{% endif %}

{# otherwise display entry #}
</code></pre>

<p>See <a href="https://craftcms.stackexchange.com/questions/6554/protect-entry-so-that-only-a-relatedto-user-can-see-it/6555#6555">this answer</a> and <a href="https://craftcms.stackexchange.com/questions/4182/password-protected-area-with-unique-files/4184#4184">this answer</a> for more options.</p>

CC BY-SA 3.0
2015-01-28T21:19:58.600Z
2015-01-28T21:44:01.033Z
2017-04-13T12:51:00.253Z
Douglas McDonald
<p>Is there a way to build a protected webpage within craft. Something that can only be accessed if you have the actual link. Something that you can not click to through the website. The point is to have a webpage that only the employees can access. Thanks for the help!!</p>

CC BY-SA 3.0
2015-01-28T21:02:05.277Z
@DouglasMcDonald Thanks for your help. Trying to post open positions in-house before they are open to the public.
Dillon van der Wal
<security>
Protected Web Page
# Protected Web Page

(Asked by: username_0 on 2015-01-28)

Is there a way to build a protected webpage within craft. Something that can only be accessed if you have the actual link. Something that you can not click to through the website. The point is to have a webpage that only the employees can access. Thanks for the help!!

**Tags:** security
> **Comments:**
> **username_0**: @DouglasMcDonald Thanks for your help. Trying to post open positions in-house before they are open to the public.  

---

## 1 answers

### Answer by username_1 on 2015-01-28. Score: 2

If you want to restrict an entire template, something like the following should work.
{% set authorized = false %}
{% if currentUser %}
    {% if currentUser.isInGroup('employee') %}
        {% set authorized = true %}
    {% endif %}
{% endif %}

{% if not authorized %}
    {% redirect 401 %}
{% endif %}

{# display template #}

Note: You can redirect anywhere with the redirect tag. I just used 401 as an example. 
If you want to designate whether specific entries are viewable then you might want to set a custom field — something like a 'lightbox' field with the handle 'public' for example.
{% set authorized = false %}
{% if currentUser %}
    {% if currentUser.isInGroup('employee') %}
        {% set authorized = true %}
    {% endif %}
{% endif %}

{% if authorized %}
    {# show non-public positions #}
    {% set positions = craft.entries.section('jobPostings').public('0') %}
    In-house Job Openings
    
        {% for position in positions %}
            {{ position.title }}
        {% endfor %}
    
{% endif %}

{# show public positions #}
Public Job Openings
{% set positions = craft.entries.section('jobPostings').public('1') %}

    {% for position in positions %}
        {{ position.title }}
    {% endfor %}


Then on the detail page (if there is a detail page), do the same:
{% set authorized = false %}
{% if currentUser %}
    {% if currentUser.isInGroup('employee') %}
        {% set authorized = true %}
    {% endif %}
{% endif %}

{% if not entry.public and not authorized %}
    {% redirect 401 %}
{% endif %}

{# otherwise display entry #}

See this answer and this answer for more options.


---

