0

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!!

1
  • @DouglasMcDonald Thanks for your help. Trying to post open positions in-house before they are open to the public. – Dillon van der Wal Jan 28 '15 at 21:02
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') %}
    <h2>In-house Job Openings</h2>
    <ul>
        {% for position in positions %}
            <li><a href="{{ position.url }}">{{ position.title }}</a></li>
        {% endfor %}
    </ul>
{% endif %}

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

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.