Navigation based on Published docs

Hi all

I’m sending on behalf of my client. This is a general question about navigation and I can’t send the url since the site is not ready.

We are using ghost 3.40.1, ghost-hosted.

Is there any way to have items in my navigation that display depending on whether they are published or not? It’s a bit of a headache to remove a menu item, unpublish the doc, then I have to re-add the item later on. I’d rather just leave the items in, then they will hide if unpublished.


No, you can’t set any condition in single nav links

Umm? Not sure what you’re asking.

He was saying it’s not possible to conditionally control (e.g. if it’s published) the navigation menu [from handlebars].

You might choose to use some javascript to control which navigation items are visible - since I don’t want to give you broken code, here’s the general algorithm:

  1. All of your pages that are linked from the navigation should have a #nav tag
  2. In your navigation area, use the get helper to fetch all published pages with the #nav tag
  3. Output the result of 2 as a script tag (e.g. final result should look like this:)
window.activeNavItems = ['slug-a', 'slug-b', 'slug-c'];
  1. Create a script that loops over the navigation elements and removes an element if the link isn’t in the activeNavItems array

Thanks, I appreciate it…will look into that.