Example /content/_index.md file please


Can someone post an example /content/_index.md file please. I’m having problems understanding what exactly needs to go into the file, so that I can display my /content/pages/*

I’ve gone through my themes examplesite (beautifulhugo theme), read the docs too, and been searching online and it simply makes no sense to me. i don’t believe that what i’m trying to do is rocket science, and i’m sure it’s a simple thing, but i simply don’t understand it :frowning:

Everything else works fine, my homepage is simply not showing the /content/pages/* entires.

Feel free to ask me for any config that I have etc.

Many thanks! :slight_smile:

.md files are for front matter & markdown, e.g. page content like setting the title or attributes in the front matter and using the main area below for text, like in a blog post. The homepage is a funny one because you might not want much in its .md file.

Your theme should (can) have a file layouts/index.html - this can be your homepage’s unique template, which is where the templating language can be used to range through your pages. So you wouldn’t put code in _index.md to display the automated list of your pages - that goes in layouts/index.html (or, if you don’t have that, _default/list.html which is the overall default listing template, but it’s nice for the homepage to have its own layout file).

1 Like
title: "This is a section"

Thank you both!

You helped me to look in the right place. The problem is that my /layout/index.html was only going to display posts where the type: post was set. As soon as I updated my post and set the type: post in the metadata, it appeared straight away on my homepage.

Only took me 4 hours to figure out, but without both of your responses, it would have taken a lot longer!

Thanks again! :smile:

1 Like

No problem! Glad you’ve been able to figure it out!

If you have a content/posts/ folder where the posts markdown files are, the default type of the content should be post because it’s in that folder, so you might not need to set it manually per item.

If the content file is in the root content folder, the default type would be ‘page’ and would therefore need set to post to override that. Going from your first comment which referred to /pages/ as what you were wanting to list out, my rough understanding is it sounds like your list loop is looking for type post, but you have overridden page types with post to make them show?

1 Like

hmm, interesting! Certainly when I create a new post by 'hugo new pages/page_name.md it’s not added to the metatags. I guess it’s easy enough to add it to the archetype file, - would that be an idea do you think, please? I’ll also try to create one later on, as i only have one page atm :joy: so i might well have deleted that tag for whatever reason.

Kinda, i had to manually place it in the metadata tag like this: type: post
and as soon as I did then my single ‘hello world’ post showed up on my homepage!

I’ll double-check everything tomorrow

It sounds like you’ve created a piece of content of type ‘page’ initially (because it’s in /pages/), which is why it’s not declaring itself as type ‘post’ when you create it. Pages are more likely to be static, one-off bits of content. A post is more likely to be an instance of something that repeats, e.g. a blog post.

It depends on what you want to achieve. If it’s pages you want to list out on the homepage, then amending the loop to range through pages and removing ‘post’ declaration from your one piece of content is the way to go.

If it’s posts you want to list out, and plan on blogging or something, then create a /posts/ content folder and have the multiple items in there (you don’t have to declare ‘post’ in the front matter), and have the loop range through posts.

At the moment you might have sort of mixed method - force-adjusting a page to become a post because the loop you have available wants posts. But everything is editable so you can construct the content strategy to fit what you want!