How can I define an anchor link through a YAML file? I would like to add a link that scrolls to the top of the sidebar (<aside>
element) from any category.
So, for example, if I'm in the HTML category, this link should get the current URL and add the anchor /#aside
. If I'm in the CSS category, the same. The resulting URL should be /html/#aside
or /css/#aside
...
This is my code:
- title: HTML
url: /html/
- title: CSS
url: /css/
- title: Index
url: */#aside
I already have an element with the ID id="aside"
in the site. And of course, this "Index" link is not working at all.
Is this even possible? (Without JavaScript)
The hash symbol starts a comment in YAML, so you'll need to quote that value. Otherwise the rest of the line will be ignored - which is probably why it isn't working:
- title: HTML
url: /html/
- title: CSS
url: /css/
- title: Index
url: "#aside"
Removing both the asterisk and the leading slash will make your link start with the hash, which will redirect to that fragment on whatever page you click it on. This is assuming you are rendering that value into the href
.
<a href="#aside">Links to the element with id="aside" on this page</a>