How should layouts be changed following the new template feature?

I have specific layouts referenced in some of my files and when upgrading from v0.145 to v0.147.1 a lot of stuff is broken.

Here’s an example.

**content**
  books
   new
    _index.md [layout = "submit/new"]
    success.md [layout = "submit/success"]

**layouts**
  books
   submit
    new.html
    success.html

I get the following error message:

ERROR [en] REF_NOT_FOUND: Ref "new" from page "/books/new": page reference "new" is ambiguous.

I have tried changing the layout path to books/submit/new but that doesn’t work. I have had a look at the GitHub release notes, but I find them confusing. Any suggestions?

1 Like

I will write a page about this in the docs repo and post a link here when I get back to my PC.

1 Like

OK, I will still do the “one pager”, but the layout set in front matter has always meant to be a name and not a path (no slashes). The path inside /layouts is reserved for the Page path. I have only seen one case of this in “the wild” before. We may find a way to imrpove this, but I’m a little surprised that this actually worked in the old setup. Your current workaround would be to flatten your custom layouts, e.g. layouts/submit-new.html.

Ok, adding to the above, a better fix for you would be to just change to layout = new and layout = success. The layout lookup will search down the file path for the correct layout.

mmh, imho you have overseen, that the folder structure for content and layouts is different. (new vs submit.

  • list page

    • content\books\ new _index.md
    • layouts\books\ submit \new.html
  • content page

    • content\books\ new \success.md
    • layouts\books\ submit \success.html

So the closest common sub folder of page and layout is content/books

With frontmatter layout = 'new' or layout = 'success' I think layouts have to be in either

  1. layouts/books/new
  2. layouts/books
  3. layouts

the template lookup order is documented here

looks like up to 0.145

0.146. is - as of now if I’m not on completely wrong track - still undocumented.

here’s something written Reimplement and simplify Hugo's template system by bep · Pull Request #13541 · gohugoio/hugo · GitHub

1 Like

Also specific methods like templates.Current’s .Name value report “new” paths for these directories and add a digit at the end, even if old paths are used.

the number seems to be a counter/index and is incremented on server rebuild

Thanks for helping out. I have tried your suggestion to do layout = new but I receive the same error message: ...page reference "new" is ambiguous

I should also add that @irkode comment is correct about the folder structure.

From reading between the lines, it seems I need to change my layout folder structure, but I’m uncertain as to how… I’ll await your page write up.

Feedback: it’s awesome to see so much growth and progress with Hugo. I have been using Hugo for many years now. At the same time, and I understand there are edge cases in how Hugo is used, but when changing what is perhaps a fundamental thing, perhaps the docs should be updated at the same time as the new changes are being rolled out?

And this is not just a comment on the template structure change. More often than not, imho, changes are made/new features are introduced, but aren’t documented, or perhaps not enough? I’ve been lucky in the past that these new changes have not impacted my project or were easy to implement, until now. For those wondering, I probably started using Hugo around v0.15-0.20.

Instead of relying on front matter, why not rely on the path?

content\books\new\_index.md
layouts\books\new\list.html

content\books\new\success.md
layouts\books\ new\page.html

In my test site, this works. :grin: cc @nobby

This will treat ALL pages with the same layout. From the initial post I guessed there’s something like a default page layout for books and some special stuff for these submit pages…

that’s why I kept the layout parameter because there might be other stuff around.

yes, that is the intention, the new design synchronizes content and layout folder structures.

so the most specific template in the closest subfolder will win… and both @tyco 's generic one and my using front matter layout will work - unless there’s nothing special around in your repo.

Depending of the complexity of your layout structure ther’s nothing wrong with staying at v0.145 and wait for the docs.