Display navigation items based on slug, page or post

Hi!
I’m trying to make a complicated blog, where I want to merge multiple WP blogs onto Ghost, since I can finally have an easier platform to write on.

On of these things I need to do, includes the navigation menu.

I’d like to only show certain navigation items, depending on what page/slug/post you’re on. I’m using content collections and have a nice setup in my routes.yaml file. It would be awesome to do this based on the whole content collection.

Let’s say I’m reading pages and posts in my English collection, I’d like to show the pages in the navigation menu (primary menu) that are in English. When I’m reading my Swedish collection, I’d like to show the Swedish pages etc.

Is this possible? Or am I dreaming here…

Wow! Cool. Unfortunately it did not work. Encounted an error, because the if helper only takes one argument. Any ideas on how to fix?

What version of Ghost is that code for? It doesn’t look like the dialect of handlebars that Ghost uses…?

Weird, just noticed that the person removed the code. How sad. I still would like if this is possible to fix. It would solve so many things.

The simplest way to do this is to check either for a tag on the post indicating language (like #es) or checking the context of the route (#is “route”).

Then, you can conditionally chain together your nav based on language (you sacrifice the ability to update the items from Ghost Admin).

{{#has tag="#es"}}
  ... Spanish nav items
{{else has tag="#en"}}
... English nav items
{{/has}}

Wow! That actually worked wonderfully. Thank you!

This makes me curious, though… how do you use the route? I tried it like this:

{{#is '/sv/'}}

But that did not work. The checking for tags did. I’m amazed!

You should be able to do {{#is 'sv'}}. This will work when you’re on the custom route. To better understand these values, you can log the current context by putting {{log this}} at the top level of your default.hbs` file.

Awesome. Yes, you have given me that tip before. The log feature is very nice. Thank you.

1 Like