Main block not rendered in custom archetype's layout

My theme’s index uses baseof.html that calls for main block. But Hugo can’t seem to find this if I call main block from a custom archetypes layout. Specifically, from projects/list.html or projects/single.html. Why is it like this?

Full repo here

Folder structure:

.
└── space
    ├── LICENSE.md
    ├── archetypes
    │   ├── default.md
    │   └── projects.md
    ├── layouts
    │   ├── 404.html
    │   ├── _default
    │   │   ├── baseof.html
    │   │   ├── list.html
    │   │   └── single.html
    │   ├── index.html
    │   ├── partials
    │   │   ├── footer
    │   │   ├── head
    │   │   ├── header
    │   │   ├── home
    │   │   └── projects
    │   └── projects
    │       ├── list.html
    │       └── single.html
    ├── static
    │   └── assets
    │       ├── css
    │       ├── fonts
    │       ├── img
    │       └── js
    └── theme.toml

Thanks for your help!

Cheers

Both your list.html and single.html only have partial calls and don’t include a main definition.

Try wrapping both of those templates in {{define "main"}}{{end}}.

@rdwatters hmmm the partial and contents are wrapped with main … took the inspiration from your theme :slight_smile:

Check out this code, not in master branch
https://github.com/vinamelody/sam/blob/improve_asset/themes/space/layouts/projects/list.html

Yeah, i was looking here when running locally. One moment:

https://github.com/vinamelody/sam/commit/87e6ca5a018ccfbf3970b81bdabdcb56cfa4a2b9#diff-bd406634bba31a94446ffd6a6fa7db04

Remove the whitespace - from the "main" definition. Works for me locally:

Oh maan … whitespace! why whitespace is causing this lol :disappointed_relieved: … and ouch the images are gone too
Thank you so much for helping @rdwatters!

Oh okay got it, so now each image should be pointed to the correct folder, such as like this <img alt="Image" src="{{.Site.BaseURL}}img/projects/001/work-8.jpg">

In a way, it might be helpful to split the statics used:

  • theme’s static should be put under themes/THEME_NAME/static/assets
  • site content’s static should be put under site’s root static

Nice! now I really excited to move forward! :smile:

Hugo uses the “define” to identify if a template needs a base template. I have improved the detection to handle your syntax in the future:

https://github.com/gohugoio/hugo/commit/0019ce002449d671a20a69406da37b10977f9493

1 Like

I see… that’s a good thing … :slight_smile: !

Btw, @bep … if in localhost this page can render properly http://localhost:1313/projects/,
why it doesn’t work after deployed into Netlify https://improve-asset–cutter-robin-15288.netlify.com/projects/ ?

I’m confused with this behavior

And that is the poor man’s regular expressions – but o so much faster.

Update: I removed all dashes - and put Hugo version 0.26 in context. Now the list.html seems to work! :tada:

Thanks a lot for your help @bep!

1 Like