Range .Pages from single template

I’m a newb, but I got pretty far with my first Hugo site and theme. I even managed to push it on to Netlify. However, the only thing that is failing is this loop:

{{ range .Data.Pages }}
  <a href="{{.Permalink}}">{{.Title}}</a>
{{ end }}

No doubt I’ve missed something I need to init before working with Netlify. But am I right in thinking that, in general, Hugo functions and loops should just work on Netlify once deployed?

In general yes. But how your loop behaves is also affected by what content gets published. For instance, on localhost I always render the website with drafts and future posts. But that’s not what gets deployed, so a loop over all pages acts a bit different in those two environments.

But other than that there should be no unexpected differences between your local build and the one on Netlify.

What does failing mean in this context? Does the loop not start, do you get odd output, are page missing, or are there pages you think shouldn’t be there? :slight_smile:



When I say the loop fails, I mean the anchor elements are not rendered in the DOM:

<a href="{{.Permalink}}">{{.Title}}</a>

Also, if I try and access the posts using the same permalink from localhost, that fails also in a 404…

You must configure the baseURL

1 Like

Right, figured it’d be something simple. I have currently:

config.toml -> baseURL = "/"

Do I need a more specific URI? Or do I need to configure this in netlify.toml as well?

You need the correct baseURL

How do I find that out?

Is this related: Correct BaseURL on Netlify previews ?

Just enter the Netlify subdomain where your project is deployed or your own domain. See the Docs.

1 Like

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.