Issues with rendering the "main" content block when using layout template

Hello!

I’m on v0.80.0.

Looking for more information on why my defined layout is not being rendered appropriately for individual blog posts making use of templates…

I have a lot of individual files defined under a single content folder:

    /content/blog/_index.html
    /content/blog/my-blog-title.html
    /content/blog/my-second-blog-title.html

These reference a layout in the frontmatter:

    layout: "post-description"

And “post-description” itself:

   {{ define "head" }}
      {{ $page := resources.Get "/css/pages/posts.css" | resources.Minify }}
      <link href="{{ $page.Permalink }}" rel="stylesheet">
    {{ end }}
    {{ define "main" }}
      <div class="example">
        hello123
      </div>
    {{ end }}

When I actually navigate to the post, what gets rendered is only the navigation and footer (defined in “baseof.html”). The title is still applied successfully. Everything under the “main” block does not get rendered at all in the HTML source, indicating that it’s not actually attempting to use the layout.

Is it only because of how the directory itself is organized? If so, is there any workaround?

We cannot tell from the description.

Please share the project to have a look at its structure, if you cannot share then post a project with dummy content that reproduces the issue.

P.S. Also please keep topic titles short and concise and use code blocks when posting code because otherwise part of it is missing. In the post editor either use the </> button or backticks.

You could tell from the description, as the issue was isolated to the directory where I already described how the files were stored in the folder. In any event, the issue is with how that directory was set up. Instead of the following:

/content/posts/

  • _index.html
  • mypost.html
  • mysecondpost.html

It needs to resemble:

/content/posts/

  • _index.html
  • mypost/_index.html
  • mysecondpost/_index.html

Otherwise it doesn’t appropriately load the layout. Thanks for taking the time to comment.

That is a bold assumption. No I could not tell from the description what is the issue and your solution above does not make sense to me.

From your second post it appears that the post-description template is meant for list pages, so basically you have turned all of your blog posts into Hugo sections, for these pages to inherit that list template.

If the outcome is what you need, all the power to you, however in the documentation there is info about the Layout Lookup Rules and the Template Lookup Order.

Anyway, please do have a look at the forum Requesting Help guidelines.

Thank you.

I have unmarked your “solution” since due to its application, you have encountered further problems and opened another support ticket while this one actually remains unsolved.

As I wrote in the other topic:

You really need to share a repo of your project.
If you cannot share it then create a repo with dummy content, that reproduces the original problem.

Please don’t make bold assumptions, yourself.

This support ticket is resolved. The other one is not related, as it is specifically with regards to iterating over subdirectories and accessing their parameters. This ticket was with regards to Hugo not correctly applying the layout when a content file is in a directory and not labeled as _index. Perhaps I did not correctly implement a solution, but it did resolve the issues I was experiencing, and resembles other directory structures I see looking online. Unless you have a better solution, it seems reasonable enough of an approach.

Regardless, given others have similar directory structures, others would likely also run across a similar need to iterate over subdirectories. No thanks to your assumptions, I did find a workaround. I created a taxonomy (“series”) and appended series: "posts" to the frontmatter, then filtered that through where .Site.Pages "Params.series" "videos". Again, if you have any better ideas and explanations as to why, I’m all ears! (legitimately! that’s why I posted the questions on these forums!) :slight_smile:

Thanks so much for your help! I really found your thoughts insightful. :wink:

Above -as well as in the other thread, that is indeed a direct continuation of this one and as such I closed it- I have asked you politely to adhere to the forum guidelines and post a sample repository as long descriptions are unhelpful.

Instead you have flagged my post in the other topic (as in you have complained about me behind-the-scenes to other @moderators ) and posted non-replies that do not really address any of the above feedback to your original issue.

At the end of the day I am a volunteer here and a line needs to be drawn.

Either @bep @moorereason @pointyfar @jmooring or any of the other @moderators in this forum will have to look into your flag, your long posts above and take whatever action they deem necessary.

Personally, I am not wasting one more second.

1 Like