How to retrieve parent folder name in Page Bundles

Hi there,

I’m now organising my content using the new Page Bundles.

I used to include a class in my element from the base filename e.g.

<article class="{{ .File.BaseFileName }}">

Which was handy for my css targeting because in the past I could apply styles to something like:

class=“contact”

Now I’m using bundles I get

class=“index”

For everything, which is expected because my leaf content is organised like:

content/contact/index.md

What I want is to recreate class="contact" in the new Page bundle content organisation approach.

I tried:

<article class="{{ .RelPermalink }}">

But I get:

class="/contact/"

I tried:

<article class="{{ .Dir }}">

But I get:

class=“contact/”

Is there a simple variable I’m forgetting that will give me the result I’m after, or do I need to add some kind of filter to remove the slashes?

If it’s the latter, would love some advice on how to do that. I’m not a regex guru.

Thanks much!

1 Like

Have not tried it in your scenario but, did you try {{ .Page.Slug }} or {{ .Slug }}?

Just gave that a try but they didn’t work.
Appreciate the help tho!

Maybe:

 {{ replace .Dir "/" "" }}

?

See:

Well that was quick and easy!
I wasn’t sure if there was a variable natively available that didn’t require an extra function but that is definitely pretty clean.
Thanks much!
:star_struck:

1 Like