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
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 %}
-
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. 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 aredisabled
. Do you have any active caching going on?– KSPCommented Nov 5, 2017 at 11:22
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 %}