Ordering content by modified date?

I’ve searched the docs but can’t find how to order content by modified date. my _default/section.html looks like this:

{{ partial "header.html" . }}
<body lang="en">
{{ partial "subheader.html" . }}

<section id="main">
  <div>
   <h1 id="title">{{ .Title }}</h1>
            {{ range .Data.Pages.GroupByDate "January 2006" }}
            <h2>{{ .Key }}</h2>
                <ul id="list">
                    {{ range .Pages.ByPublishDate }}
                        {{ .Render "li"}}
                    {{ end }}
                </ul>
            {{ end }}
  </div>
</section>

{{ .Lastmod.Format "20060102-15:04:05.000" }}
<aside id="meta"> </aside>
{{ partial "footer.html" . }}

@breschke doing this from mobile, so I’m not 100%, but I believe sorting for pages goes weight > date, so sorting by modify date isn’t quite as easy. That said, I know that @moorereason gave me a similar response on a similar question.

Ordering by mod date (lastmod set in frontmatter, defaults to date) hasn’t been easy, if at all possible.

I just added a sort func for this.

See

And

doc in

I re-installed hugo from github to take advantage of this new sort function. I tried creating a new site and then using a modifed hyde-x theme with the following in layouts/_default/list.html:

{{ partial "head.html" . }}
<div class="content container">
  <ul class="posts">
  {{ range .Data.Pages.ByLastmod }}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a>
    {{ if isset .Params "categories" }}
    &middot;
    {{ range .Params.categories }}<a class="label" href="{{ "/categories/" | absURL }}{{ . | urlize }}">{{ . }}</a>{{ end }}
    {{ end }}</span>
    &middot; <time>{{ .Date.Format "Jan 2, 2006" }}</time></li>
  {{ end }}
  </ul>
</div>
{{ partial "foot.html" . }}

But when I start the server, I get the following error:

ERROR: 2016/04/22 Error while rendering section post: template: theme/_default/list.html:4:16: executing "theme/_default/list.html" at <.Data.Pages.ByLastmo...>: can't evaluate field ByLastmod in type interface {}

Which indicate you don’t have the latest source build.

OK, I managed to correctly install the latest source build and I no longer get an error. But the function appears to have no effect on the order of posts. MWE posts with the above list.hmtl layout:

1:

+++
date = "2016-04-20T13:43:35-06:00"
lastmod = "2016-04-20T13:43:35-06:00"
draft = true
title = "first"

+++

Testing 123

2:

+++
date = "2016-04-21T13:43:35-06:00"
lastmod = "9999-04-21T13:43:35-06:00"
draft = true
title = "next"

+++

Testing 456

3:

+++
date = "2016-04-22T13:43:35-06:00"
lastmod = "2016-04-22T13:43:35-06:00"
draft = true
title = "last"

+++

Testing 789

The post ‘next’ still appears in the middle.

I’ve got the very newest version 0.24 and .ByLastmod does nothing for me on my list templates. Is there any sort of trick that I need to utilize? .Lastmod is usable in my .Render call and on my single.html, but it just won’t sort by it. Right now I’m using weight to try to feature recently modified stories but it’s not ideal.

I’m using the code shown in the middle of https://gohugo.io/templates/list/

{{ range .Data.Pages.ByLastmod }}
  <li>
    <a href="{{ .Permalink }}">{{ .Title }}</a>
    <div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
  </li>
{{ end }}

There is no difference between that and the regular sort.

This may be wrong in light of the replies already posted. But I am using the following:

date: I am using this as the last mod. So I update this on modification. It is used in sitemap and sort by detail.
publishdate: The initial publish date.

Isn’t this the easiest solution, or am I missing something obvious (only been using gohugo for 3 weeks or so)?

I had the same problem as @epatr

I enabled enableGitInfo = true in config.toml, and .Lastmod can retrieve the modified date correctly. However, the
Data.Pages.ByLastmod does not work.
I guess there’s no lastmod in my frontmatter and ByLastmod doesn’t retrieve .Lastmod.