Range .Pages from single template

OK, I have so far tried to add the following patterns to config.toml -> baseURL:

  1. https://my.domain.com
  2. my.domain.dom
  3. my-netlify-sub-domain.netlify.com
  4. http://my.domain.com/

But unfortunately, all 3 attempts failed to fix my loop…

And when you say Docs, do you mean Netlify or Hugo docs? I have so many Doc tabs open. If you have a link, please send.

You have to have a trailing “/” or it won’t work.

Netlify uses www

You enter https only if you have configured a TLS certificate for your domain.

I was referring to the Hugo Docs.

If your problem persists then please post a link to your repo.

OK, still struggling here:

Site: https://pedantic-leavitt-3a9909.netlify.com/

Repo: https://github.com/jnthnclrk/nut001

config.toml: baseURL = "https://pedantic-leavitt-3a9909.netlify.com/"

404s on posts still: https://pedantic-leavitt-3a9909.netlify.com/posts/16-medical-benefits-marijuana/

Also, the loop is still failing…

@alexandros do you have a link to the Hugo Doc that speaks to this problem?

Hostname (and path) to the root, e.g. http://bep.is/

But I’m not sure that your problem is related to configuring the baseURL.

I wanted to test your repo locally but something is wrong with GitHub right now and I cannot clone it.

Anyway I took a cursory look earlier.

The one thing that seemed a bit weird to me was that you have defined the Ananke theme as a git submodule and yet you use another theme for your project.

Try setting the theme you use as a submodule and see if that fixes your deployment on Netlify.

Agreed, I’ve tried all baseURL options possible. And most of the other themes I reference set the baseURL to “/”.

True, Ananke is installed, but unsused.

The other theme, nut001, is built from scratch using Hugo quicktstart and Bootstrap. Does it really need to be installed as a submodule?

GitHub is coming back up…

I don’t think so. The submodules are meant for external themes so that you can receive updates. Since this is your custom theme I suppose that you could simple delete that submodule file.

Anyway I managed to download your repo. So far no console errors but let me have a look.


Ok. You have no template for single pages hence the 404 for your post at https://pedantic-leavitt-3a9909.netlify.com/posts/16-medical-benefits-marijuana/

Also your index page is full of dummy posts.

Please familiarize yourself with Hugo’s single page templates lookup order and create that template.

Also your /layouts/_default/list.html template is blank. You MUST have a list template for your posts to show up on your site.

I’ve searched your theme directory and there is no instance of the following:

What is the problem again?

Single template is here: https://github.com/jnthnclrk/nut001/blob/master/themes/nut001/layouts/posts/single.html

{{ range $.Data.Pages }} is in: https://github.com/jnthnclrk/nut001/blob/master/themes/nut001/layouts/partials/header.html

The above templates work great in the Hugo server on localhost.

That said, I understand I might be doing this is a non standard way. Not sure what happened between the Hugo Quickstart and now. I’ll review my steps.


On my end the URL http://localhost:1313/posts/16-medical-benefits-marijuana/ threw a 404 locally.

I had to delete draft = "true" from the post’s front matter.

So here is why that page got a 404 on Netlify. Drafts are not published.

As for your missing loop:

First, you do not need the dollar sign ($). You would use that if you where within a shortcode to go higher up.

Second .Data.Pages is for list pages not single pages.

You should use .Site.Pages for a single page template to render other pages.

[ Not entirely unrelated note. Hey @kaushalmodi (thought you wanted to see this) here is a use case where simply using {{ range .Pages }} doesn’t return anything only .Site.Pages returns results ]

But anyway @jnthnclrk are you sure you want to display post permalinks in your header? You will need 2 different headers with such a design. One for single pages and one for lists. Not very DRY (Don’t Repeat Yourself)

Also see related topic about .Data.Pages vs .Site.Pages from a single page template:

1 Like

I don’t have the full context – {{ range .Pages }} would get pages only from the current… um… context, whereas {{ range .Site.Pages }} will get all pages from the site regardless of the current context.

So {{ range .Pages }} might not return all site pages if it’s placed in a narrower context.

1 Like

The current context is a single page.

P.S. I renamed this thread to something more appropriate since it had nothing to do with Netlify after all.

Yep, then that returning nil makes complete sense… A single page never contains a slice of other pages (talking strictly about .Pages here).

Update: See this table for more info.

1 Like

You should merge that table in the Docs.

@alexandros you nailed it! My original problems were two fold:

  1. My posts were draft - DOH!
  2. I was using the wrong function across single and list pages

Thing is, .Site.Pages works on both single and list pages. So instead of writing 2 header partials, I may as well keep that.

.Site.Pages will fetch all pages. Including static pages such as About or Contact that you may not want included.

In any case you should probably limit what is returned by your range function, there are plenty of examples in the Docs.