3

I'd like to show a 'Jobs' link in my navigation only if the Jobs page is enabled. Is there a way for craft to detect if the page is enabled, and show a div?

2 Answers 2

6

You can check the status of an entry with .status. https://craftcms.com/docs/templating/craft.entries#status

This code should work!

{% set jobsEntry = craft.entries.id(jobsId) %}

{% if jobsEntry.status == 'live' %}
    <a href="{{ jobsEntry.url }}">Jobs</a>
{% else  %}
    Jobs is disabled
{% endif %}
2
  • Thanks! The code definitely works, but my link still shows even though I disabled the entry. And the page still shows up even though the entry's status is disabled. I thought marking it as 'disabled' would at least not let it show in the browser.
    – kingkelly
    Commented Nov 3, 2017 at 18:17
  • That sounds strange – when you specifically ask only for entries that are live, it shouldn't show entries that are disabled. Do you have any active caching going on?
    – KSP
    Commented Nov 5, 2017 at 11:22
2

I ran into the same problem where if a page was 'disabled', I didn't want it to show in my footer navigation. The recommended answer didn't work for me. The link still showed up. The following worked:

{% set myEntry = craft.entries.id(entryId).first() %}

{% if myEntry %}
    <li><a href="example.com">Example</a></li>
{% 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.