other range options?

38 views
Skip to first unread message

Trent Nelson

unread,
Sep 14, 2014, 12:19:07 AM9/14/14
to hugo-d...@googlegroups.com
Hey gang, I'm loving Hugo. Just converted a 3,000+ post blog from wordpress and it's been fun.

I've read everything I could find and couldn't find a solution for this approach.

I know how to pull the first post, or the first ten posts. Like this:

      {{ range first 10 .Data.Pages }}

Is there a way to pull posts 2-10?

On my front page I'm displaying the most recent post at top and want to show the previous nine posts in a list.

Any help much appreciated, and thanks to everyone who has made Hugo so awesome!
-trent

Alex Dunn

unread,
Sep 14, 2014, 5:19:22 PM9/14/14
to hugo-d...@googlegroups.com
Something like this should work:

```
{{ range $index, $value := first 10 .Data.Pages }}
{{ if ( gt 0 $index ) }}
{{/* do whatever */}}
{{ end }}
{{ end }}
```

I didn't test that, but I'm pretty sure it's right.

Trent Nelson

unread,
Sep 15, 2014, 1:15:17 PM9/15/14
to hugo-d...@googlegroups.com
Thank you Alex!!

Using your code and a little help from a genius to tweak it, here is what I used to pull the most recent posts numbered 2-4, 5-7, 8-10 into three different divs.

{{ range $index, $value := first 4 .Data.Pages }}
{{ if ( gt $index 0 ) }}
{{ .Render "li" }}
{{ end }}
{{ end }}


{{ range $index, $value := first 7 .Data.Pages }}
{{ if ( gt $index 3 ) }}
{{ .Render "li" }}
{{ end }}
{{ end }}


{{ range $index, $value := first 10 .Data.Pages }}
{{ if ( gt $index 6 ) }}
{{ .Render "li" }}
{{ end }}
{{ end }}



Reply all
Reply to author
Forward
0 new messages