Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

One-page Navigation link to off-page

Started by Muut Archive 12 years ago · 11 replies · 622 views
12 years ago

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.

12 years ago

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

12 years ago

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?

12 years ago

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

12 years ago

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

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

Then in your twig file you would output them like:

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

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

11 years ago

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!

11 years ago

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.

11 years ago

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

11 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1321 9 years ago
Archive · by Muut Archive, 9 years ago
2 916 9 years ago
Archive · by Muut Archive, 9 years ago
2 4047 9 years ago
Archive · by Muut Archive, 9 years ago
1 2921 9 years ago
Archive · by Muut Archive, 9 years ago
3 1105 9 years ago