eleventy
eleventy copied to clipboard
How To Reach Parent Folder?
I have this nested section ->
content/
|_blog/
| |_index.md
|_poem/
|_2020
|_2020.json
|_new-poem.md
When I'm on domain.tld/new-poem/ page, how to reach parent folder "poem" and "2020"?
I think you should add an _index.md into _2020 directory (or any other index, depends on you template language). This will add an access to /2020 path. The same for _poem.
Or another solution is to add a _2020.md into _poem directory and _poem.md into content directory. Works for me.
I think you should add an
_index.mdinto_2020directory (or any other index, depends on you template language). This will add an access to /2020 path. The same for_poem.Or another solution is to add a
_2020.mdinto_poemdirectory and_poem.mdintocontentdirectory. Works for me.
Yes, it's reachable with that method. But I mean, how to reach them via parameter?
So, if I make a button from domain.tld/new-poem/ page, I can reach domain.tld/poem/ and domain.tld/poem/2020/ right from that page.
I try to add {{ parent }} and {{ parent.url }} but it doesn't works?
@BayuAngora I must not be understanding...
If you're on "domain.tld/new-poem/" and you wanted to reach "domain.tld" poem, wouldnt you just use <a href="/poem/">something</a>?
Not sure where you're trying to access {{ parent }}, if it's in an href or elsewhere.
@BayuAngora I must not be understanding... If you're on "domain.tld/new-poem/" and you wanted to reach "domain.tld" poem, wouldnt you just use
<a href="/poem/">something</a>?Not sure where you're trying to access
{{ parent }}, if it's in anhrefor elsewhere.
Yes, I can use that to reach "/poem/" folder. But if I want to reach "/poem/2010/" and "/poem/2011/" and "/poem/2012/" and more, I have to implement it one by one. Or at least one layout for every folder.
I have hundred poems that spread to several (sorted by year) folder.
With Hugo, I can implement it by {{ .Parent.Title }} and {{ .Parent.URL }}. So, everytime I post a new poem in every year folder, it can be detected and sorted automatically.
I don't know how to implement it with Eleventy?
Has anyone figured this out? I'm trying to do something similar. The Hugo example is exactly what I'm trying to accomplish as well.
On Hugo I can implement it with this code:
<a href="{{ .Parent.Permalink }}">
<h2>{{ .Parent.Title }}</h2>
</a>
I still curious how to implement it on 11ty.
Lots of overlap with #3794 here but this makes me think it might be more useful to have a supplied universal filter to get the parent directory of a path or URL.