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

Directory relative links between pages

Started by Muut Archive 11 years ago · 8 replies · 563 views
11 years ago

I am trying to generate links between pages using the method explained in http://learn.getgrav.org/content/linking

None of the methods (directory relative nor absolute) I tried resolve the link correctly and the URL is the unprocessed/unresolved directory entry rather the page's default route.

For example if I have a page in /pages/02.green/01.grass/default.md I expected to get the url configured as default route when generating links or the slug if no default route given.

But when using:

[Some link](01.grass/default.md) generates /02.green/01.grass/default.md
or
[Some link](01.grass) generates /02.green/01.grass
or
[Some link](/02.green/01.grass) generates /02.green/01.grass

Is there a setting I overlooked which turns on link processing?

11 years ago

First, it's much better not to use the actual folder directories. This is because if you change the directory or change the ordering, it will break your links. Better to use the route.

So, for your example page in pages/02.green/01.grass/default.md the route to this (as shown in your browser) is: /green/grass. So from some other page the simplest way to reach this page is via:

TXT
[Some link](/green/grass)

That's all there is to it.

11 years ago

Yes, but we have different needs for inter-page linking and were hoping the methods described in http://learn.getgrav.org/content/linking would work.

1) Using the proposed slug method would still not resolve the link to be rendered with the default route set in the page header:

YAML
title: A web page
routes: 
   default: /my/web/1234-page-with-a-very-long-url-which-may-change

2) Are the methods for directory relative and absolute page linking described in http://learn.getgrav.org/content/linking actually working?

The examples described in the documentation are

MARKDOWN
[link](../../02.green/01.grass/item.md)
[link](/01.blue/01.sky)
[link](../../02.green/01.grass)
[link](../../02.green)
[link](../../02.green)

3) I am hoping for a method which can generate the default route of a page based on some form of handle or identifier. It does not matter for us if that is the file name or the slug or even a page id of some form. This all should work in a multi-languag e context were the default routes are different for the languages but still the page's file name, slug or handler or id would be the same.

11 years ago

Well in my test they are all working fine. Obviously the example below is based on my testing site, but you can get an idea of the various link types:

MARKDOWN
### Directory relative

* just down [01.item2-1](01.item2-1)
* just up [..](..)
* file link with [../../03.blog/2015-01-11-atom-vs-coda/item.md](../../03.blog/2015-01-11-atom-vs-coda/item.md)
* up more and down more no filename but hash [../../03.blog/focus-and-blur#something](../../03.blog/focus-and-blur#something)
* up and down no filename [../03.assets](../03.assets)
* up more and down more no filename but query + hash [../../03.blog/focus-and-blur?foo=bar#something](../../03.blog/focus-and-blur?foo=bar#something)
* file link [../../03.blog/focus-and-blur/item.md](../../03.blog/focus-and-blur/item.md) {.button}

### Slug relative

* up and down with [../../blog/atom-vs-coda](../../blog/atom-vs-coda)
* up and down with param [../../blog/tag:birds](../../blog/tag:birds)
* up and down with anchor [../smartypants#someanchor](../smartypants#someanchor)
* up and down with query [../smartypants?foo=bar&cat=brown](../smar typants?foo=bar&cat=brown)
* up and down into smartypants [../smartypants](../smartypants)
* up more and down more [../../blog/focus-and-blur](../../blog/focus-and-blur)
* just down [item2-1](item2-1)

<a name="test" class="anchor"></a>
## Absolute

* absolute link: [/blog/focus-and-blur](/blog/focus-and-blur)
* absolute link with param: [/blog/tag:birds](/blog/tag:birds)
* absolute with paths: [/03.blog/2015-01-11-atom-vs-coda/item.md](/03.blog/2015-01-11-atom-vs-coda/item.md)
* absolute with relative: [/08.test/../03.blog/2015-01-11-atom-vs-coda/item.md](/08.test/../03.blog/2015-01-11-atom-vs-coda/item.md)
* absolute link + query: [/blog/focus-and-blur?foo=bar](/blog/focus-and-blur?foo=bar)
* absolute with paths + query: [/03.blog/2015-01-11-atom-vs-coda/item.md?foo=bar](/03.blog/2015-01-11-atom-vs-coda/item.md?foo=bar)

### Hash Links

* relative hash [../page-links#test](../page-links#test)
* relative hash [../page-links/#test](../page-links/#test)
* just a [#test](#test)
* root hash [/#test](/#test)

### Reference links

* [../03.assets#blah][r_relative]
* [/blog/focus-and-blur#blah][r_absolute]
* [http://www.cnn.com][r_external]

### Other link types

* [xmpp:[email protected]](xmpp:[email protected])
* [tel:1-555-223-2323](tel:1-555-223-2323)
* [sms:1-555-223-2323](sms:1-555-223-2323)
* [mailto:[email protected]](mailto:[email protected])

### Remote

* remote http: [http://www.cnn.com](http://www.cnn.com)
* remote https: [https://github.com](https://github.com)
11 years ago

Scratch that last commit, had to roll that back as it broke image links. I'll look to find a way to add active language prefix for markdown links only.

11 years ago

Not sure what's wrong with my installation. I added a directory /user/page/03.blog/2015-01-11-atom-vs-coda with a file item.md
and then this markdown link to the home page which I copied from above example:

TXT
[/03.blog/2015-01-11-atom-vs-coda/item.md](/03.blog/2015-01-11-atom-vs-coda/item.md)

but the link resolves to simply plain-text http://localhost/03.blog/2015-01-11-atom-vs-coda/item.md with a 404 of course instead of the correct http://localhost/blog/2015-01-11-atom-vs-coda

Is there a plugin of some sort which must be installed/enabled for link generation? Grav is latest 0.9.42.

11 years ago

Nope, shouldn't need anything special.

Can you do me a favor, please zip up your site, drop it on dropbox (or similar) and send me a link to andy at getgrav dot org.

Then I'll check it out on my local and see if I can spot what's going on.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1338 9 years ago
Archive · by Muut Archive, 9 years ago
2 927 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago