One-page Navigation link to off-page

I’m using the one-page skeleton and I’d like to link to a page (News) from the top header. I tried that blog post of yours where you can set a route but I couldn’t get it to work due to the hashtag.

You can add a link to the templates/modular.html.twig file where the menu is being generated.

Hmm but not through page headers? Something like this: https://github.com/nebman/pico-redirect

Well you could do something in the page headers. In Grav you don’t actually need a plugin to do a redirect but I don’t think this really what you are looking for, just custom non-on-page menu items.

You could create an array of menu items in the modular.md page header, and then loop through these in the modular.html.twig template after the on-page links, to display those other links (such as news/blog/whatever).

Does that help?

How would I redirect without a plugin? I could want to go to an off-site link as well.

Just create your array of extra menu links in the header like this:

menu_links:
  'Internal Link': /some/internal/link
  'External Link': http://www.somesite.com/

Then in your twig file you would output them like:

{% for text,link in page.header.menu_links %}
    <li><a href="{{ link }}">{{ text }}</a></li>
{% endfor %}

Okay, I will try that out. Thanks for the help, this is a really great platform.

Thanks!

Would it be possible to scan for and (e.g. h2) headlines from the markdown’s content/raw_content instead of the page.header.menu_links? Thanks in advance!

That could be possible. This question was originally regarding modular content, and as such the menu was intended to link to the top of each modular section. That is how it works now, and it makes sense to use the menu: attribute of each modular page.

If your asking about providing a one page menu for a single page, and triggering the menu to jump to headline tags, that’s possible if you create a plugin that uses say the onPageContentProcessed() event. It could perform a regex to find all tags that you want to trigger on, insert a target link: <a name="#my-headline"></a>, and then also build up an array of these headlines and store them on the page.

Then you could simply access this array from some navigation code, and display those headlines and link to the appropriate page target.

So yes, it can be done, and really it wouldn’t be that difficult. However, it is quite a specific thing your asking about, and I know of no plugin currently that does this.

Thank you very much! I guess from now on there are no more ways around your plugin tutorial. :slight_smile:

it’s really very simple. Check out some of the existing plugins to see how varied and powerful they can be.