1

I have projects on my portfolio that link to each other. I'm currently using previous and next links.

This is what my code looks like

{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('portfolio') %}
{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

And then I call it to display it in my code like so:

<div class="projectsNavigation">
    {% if prevEntry %}
    <div class="previousProject">
        <a href="{{ prevEntry.getUrl() }}">
            <span class="visibleText">Previous</span>
            <span class="projectTitle">{{ prevEntry.client }}</span>
        </a>
    </div>
    {% endif %}
    {% if nextEntry %}
    <div class="nextProject">
        <a href="{{ nextEntry.getUrl() }}">
            <span class="visibleText">Next Project</span>
            <span class="projectTitle">{{ nextEntry.client }}</span>
        </a>
    </div>
    {% endif %}
</div>

My goal today is to hide the previous entry button if the previous entry has the comingSoon lightswitch field ON.

1 Answer 1

1

I got it by simply adding a condition where I was displaying my previous entry.

{% if prevEntry %}

    {% if prevEntry.comingSoon %}

        {# if comingSoon field is active, hide the link #}

    {% else %}

    <div class="previousProject">
        <a href="{{ prevEntry.getUrl() }}">
            <span class="visibleText">Previous</span>
            <span class="projectTitle">{{ prevEntry.client }}</span>
        </a>
    </div>

    {% endif %}
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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