Dynamically Showing Navigation Pages via Access

Hey Ghost community! If this isn’t the right category for this question, let me know - still new :slightly_smiling_face:

I am working on a custom theme and was looking into the documentation for the {{ navigation }} helper and it looks like you can loop through the nav items in the helper.

However, it didn’t look like I could do any logic only show nav items that members have access to based on what I had access to in the page.

If I wanted to do this, would I have to hardcode my menu items in my navigation component and then wrap relevant menu items in a {{#match member}} helper to accomplish what I’m looking to do?

Really interested in your thoughts - thanks!

Have you checked out the @member object?

You can use it like this:

{{#match @member}}
  <a href="something-only-for-a-member">Link</a>

{{#match @member.paid}}

Not sure if that’s what you already tried and found something that didn’t work with it. If so, let us know.

Ryan, I think they’re wanting to have output the navigation links but check if they’re accessible and only show the ones the member has access to.

@iambradfyi, I think this is one of those spots where it’s going to be tricky and/or slow to do it with handlebars. Since your site’s top navigation probably doesn’t change very often, I think this is a spot where it makes sense to hard code what links there are, and wrap each one with the handlebars logic as Ryan shows, rather than trying to figure out live on the fly whether the user has access to each.

{{Navigation} doesn’t really parse where the links it has actually go (and indeed, they can even go off site), so it’s going to be a big lift to make it understand that a particular link corresponds to a specific Ghost page and then check the user’s access to that page…

Hey @RyanF - thanks for responding! As I’ve been digging into the forum as a new member, you’ve shown up to help a lot of people. I started reading your blog and am learning a lot more about web development. Thanks for all that you put out there!

This is the exact solution I implemented while hardcoding specific links. I was hoping to base access from the page object, which I don’t have access to in the Navigation helper. :slight_smile:

@Cathy_Sarisky Thanks for jumping in again! I hadn’t considered the fact that you could have a nav item that isn’t on your site. That makes sense and I think that confirms my path with hardcoding the navigation component.