Using relref with _index.md files

Hi,

I am new to Hugo and I am having issues with _index.md. I am trying to build a simple website (not a blog) for a hotel and creating my own theme along the way.

So far the themes/hotel/layouts folder contains:

layouts/index.html
layouts/_default/single.html
layouts/partial/header.html
layouts/partial/menu.html
layouts/partial/footer.html

and the contents folder contains:

contents/_index.md
contents/rooms/_index.md
contents/rooms/single.md
contents/rooms/double.md
contents/contact.md

At the end I want the HTML pages to be created to be:

public/index.html
public/rooms/index.html
public/rooms/single/index.html
public/rooms/double/index.html
public/contact/index.html

In the theme’s menu.html template (included using partial in index.html and single.html), I am trying to add a link to all the pages of the website. This works:

<a href="{{ relref . “contact.md” }}">Contact
<a href="{{ relref . “rooms/single.md” }}">Contact

but I don’t manage to get a link to the pages created from _index.md:

<a href="{{ relref . “_index.md” }}">Homepage
<a href="{{ relref . “rooms/_index.md” }}">Our rooms

returns an error "error calling relref: No page found with path or logical name “_index.md”.

I read the doc and some of the posts here regarding “_index.md” but there is clearly something I don’t understand so I would be grateful if someone could shed some light on this for me.

Also if there is a particular section of the documentation or a particular theme that could be useful for the kind of website I am trying to build, please let me know.

Many thanks for developing Hugo!

I guess the cross references doc doesn’t explicitly say so, but it points to single content, not index pages.

Check out the section menu for lazy bloggers for an example of what you are trying to do. :slight_smile:

1 Like

Thanks Maiki!

I realised that the public/rooms/index.html was not even generated so I added a layouts/_default/list.html file.
I tried adding the code from section menu for lazy bloggers and it created one line:

<a href="/rooms/">Title of rooms' page</a>

so I guess I have a way out now but I still don’t know how it would work if I had more than one _index.md page (eg for /rooms/ and /restaurants/): instead of

range .Site.Menus.main

I guess it should be a test whether the menu corresponds to rooms/_index.md?

As for the link to the homepage layouts/_index.md, should I just use:

<a href="/">Home</a>

Thank you for the help.

Ya know, slugs of pages may change if they are updated, and the ref shortcodes are there to accommodate those. But how often are you gonna change your sections? I feel it becomes an IA issue, before a link to the correct URI issue, ya know?

So I would link to the home and sections hard (or over a range if that works), rather than trying to get ref to work. :slight_smile:

1 Like

Thanks, that’s a fair advice. I will use hard coded links for the moment - I’m just trying to get my head around Hugo by using more and more of its features.
Just to be complete, I also found this about a similar issue.