# What am I doing wrong? Lookup order issue, with complete example

**URL:** <https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210>\
**Category:** support\
**Created:** [February 25, 2019, 2:20pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210 "2019-02-25T14:20:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dotleon](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dotleon](https://discourse.gohugo.io/u/dotleon)\
**Post date:** [February 25, 2019, 2:20pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/1 "2019-02-25T14:20:23Z")

</div>

I’ve read the documentation, I’ve searched the topics, but it’s still not clear why is the lookup order is wrong.

Here’s this example: [https://github.com/dotleon/leafbundlelayoutissue](https://github.com/dotleon/leafbundlelayoutissue)

According to the documentation, this is the lookup order for the “/leafbundle/” in the example:

> Single page in “posts” section  
> layouts/posts/single.html.html  
> layouts/posts/single.html  
> layouts/\_default/single.html.html  
> layouts/\_default/single.html

This means that “/content/leafbundle/index.md” should render from “/layouts/leafbundle/single.html”. But it renders from “/\_default/single.html” instead.

For whatever reason, this works right with a branch bundle, see /branchbundle/ in the example.

I feel like the documentation is in the wrong here, as /\_default/ gets priority over /leafbundle/, but only if I use “index.md” (leaf bundle) instead of “\_index.md” (branch bundle).

This got closed as an issue, so I suppose it’s my understanding of the lookup order that is wrong, but I couldn’t figure this out the whole day.

Could somebody explain why /leafbundle/ is not working in my example as one would expext?

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [February 25, 2019, 5:34pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/2 "2019-02-25T17:34:25Z")

</div>

Others please correct me if I’m wrong, but this is what I think is happening.

So this file:

```nohighlight
content/leafbundle/index.md

```

Is equivalent (layout-wise) to this file:

```nohighlight
content/leafbundle.md

```

In both cases, the `layouts/_default/single.html` template will be used.

Now, if you delete that content file, then create:

```nohighlight
content/leafbundle/some-post.md

```

You will get the result you’re expecting, aka the `layouts/leafbundle/single.html` template will be used.

This is because `content/leafbundle/some-post.md` is actually a leaf bundle, whereas your previous content file is not. Hope this helps.

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [February 25, 2019, 6:43pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/3 "2019-02-25T18:43:39Z")

</div>

[https://discourse.gohugo.io/t/my-experiences-with-hugos-template-lookup-order/9959/3](https://discourse.gohugo.io/t/my-experiences-with-hugos-template-lookup-order/9959/3)

Hope this helps

---

<div class="post-metadata">

**Author:** ![dotleon](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dotleon](https://discourse.gohugo.io/u/dotleon)\
**Post date:** [February 25, 2019, 7:05pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/4 "2019-02-25T19:05:14Z")

</div>

> [@Leo\_Merkel](#):
>
> [My experiences with Hugo's template lookup order - #3 by nklamann](https://discourse.gohugo.io/t/my-experiences-with-hugos-template-lookup-order/9959/3)
> 
> Hope this helps

It doesn’t really help, as you create an \_index.md too, which is a branch bundle. Branch bundle templating lookup works as expected, as documented.

Leaf bundles don’t.

---

<div class="post-metadata">

**Author:** ![dotleon](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dotleon](https://discourse.gohugo.io/u/dotleon)\
**Post date:** [February 25, 2019, 7:08pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/5 "2019-02-25T19:08:43Z")

</div>

> This is because `content/leafbundle/some-post.md` is actually a leaf bundle, whereas your previous content file is not. Hope this helps.

From the documentation:

> Leaf Bundle  
> Usage: Collection of content and attachments for single pages  
> Index file name: index.md

also

> A _Leaf Bundle_ is a directory at any hierarchy within the `content/` directory, that contains an **`index.md`** file.

I’m still not convinced. This still very much sounds like a bug. Either in the documentation, or the way it actually works.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [February 25, 2019, 7:18pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/6 "2019-02-25T19:18:26Z")

</div>

I can see the potential confusion.

cc @kaushalmodi as he will likely have a better explanation.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 25, 2019, 7:25pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/7 "2019-02-25T19:25:59Z")

</div>

> [@dotleon](#):
>
> This means that “/content/leafbundle/index.md” should render from “/layouts/leafbundle/single.html”.

No, think of `/content/leafbundle/index.md` as `/content/leafbundle.md` **but** as a Leaf Bundle. `/content/leafbundle/index.md` is not technically inside a “leafbundle” section.

… `/layouts/leafbundle/single.html` applies to **pages** in ` leafbundle` “section”.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [February 25, 2019, 7:33pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/8 "2019-02-25T19:33:01Z")

</div>

If you look at this table:

> **[Hugo's Lookup Order](https://gohugo.io/templates/lookup-order/#examples-layout-lookup-for-regular-pages)**
>
> Hugo searches for the layout to use for a given page in a well defined order, starting from the most specific.

Look at the row with “layout” in it. There is no “layout in folder lookup” in any of those variations.

---

<div class="post-metadata">

**Author:** ![dotleon](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dotleon](https://discourse.gohugo.io/u/dotleon)\
**Post date:** [February 25, 2019, 7:54pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/9 "2019-02-25T19:54:40Z")

</div>

> Single page in “posts” section with layout set
> 
> - layouts/posts/demolayout.html.html
> - layouts/posts/single.html.html
> - **layouts/posts/demolayout.html**
> - **layouts/posts/single.html**

> `/content/leafbundle/index.md` **is not technically inside a** “leafbundle” **section**.

This is the part I couldn’t comprehend up until this point. I think I understand now.

I really appreciate all of your input, things can get a little confusing until you have a solid grasp of what’s what.

I’ve managed to get over this issue by putting the demolayout.html into the \_default folder, but it really bugged me that I didn’t understand why it’s not working, but now I do.

I’ve always hated web programming, but with hugo I’m actually enjoying it.

Thank you for helping!

PS: awesome community

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [February 25, 2019, 9:56pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/10 "2019-02-25T21:56:15Z")

</div>

That said, you may want to look into setting `Type` in front matter (aka `posts` in the example).

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [February 25, 2019, 10:00pm UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/11 "2019-02-25T22:00:31Z")

</div>

In addition you might want to look at this great explanation from @regis:

> **[Hugo Page Resources, and how to use them... | Regis Philibert](https://regisphilibert.com/blog/2018/01/hugo-page-resources-and-how-to-use-them/)**
>
> In this article we'll cover Hugo 0.32's Page Resources and its impact on the way we structure our content folders, what methods and properties it offers, how to use it in our templates and markdown and finally its newly metadata logic!

---

<div class="post-metadata">

**Author:** ![relloyd](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@relloyd](https://discourse.gohugo.io/u/relloyd)\
**Post date:** [January 30, 2020, 11:51am UTC](https://discourse.gohugo.io/t/what-am-i-doing-wrong-lookup-order-issue-with-complete-example/17210/12 "2020-01-30T11:51:51Z")

</div>

I found exactly the same issue. Thanks @dotleon and everyone for working through this!

My scenario was essentially trying to create a new layout by converting `content/post-xyz.md` to `content/post-xyz/index.md`, which lead me to think that we can just use `layouts/post-xyz/single.md` because this documentation page about [Page Bundles](https://gohugo.io/content-management/page-bundles/) shows that a leaf bundle is just a page of type `single`.

So long story short - the simple option is just to use:

1. an explicit front matter entry `layout = post-xyz` in `index.md` above
2. add `layouts/_default/post-xyz.html`
