eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

How To Reach Parent Folder?

Open BayuAngora opened this issue 5 years ago • 6 comments

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"?

BayuAngora avatar May 29 '20 02:05 BayuAngora

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.

dtroode avatar May 29 '20 07:05 dtroode

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.

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 avatar May 29 '20 07:05 BayuAngora

@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.

pdehaan avatar May 29 '20 08:05 pdehaan

@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.

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?

BayuAngora avatar May 29 '20 10:05 BayuAngora

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.

simplerethink avatar Jan 06 '23 01:01 simplerethink

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.

BayuAngora avatar Jan 08 '23 14:01 BayuAngora

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.

zachleat avatar Nov 21 '25 18:11 zachleat