github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/after.md (about) 1 --- 2 title: after 3 description: "`after` slices an array to only the items after the <em>N</em>th item." 4 godocref: 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-02-01 8 categories: [functions] 9 menu: 10 docs: 11 parent: "functions" 12 keywords: [iteration] 13 signature: ["after INDEX COLLECTION"] 14 workson: [] 15 hugoversion: 16 relatedfuncs: [last,first,seq] 17 deprecated: false 18 aliases: [] 19 --- 20 21 The following shows `after` being used in conjunction with the [`slice` function][slice]: 22 23 ``` 24 {{ $data := slice "one" "two" "three" "four" }} 25 {{ range after 2 $data }} 26 {{ . }} 27 {{ end }} 28 → ["three", "four"] 29 ``` 30 31 ## Example of `after` with `first`: 2nd–4th Most Recent Articles 32 33 You can use `after` in combination with the [`first` function][] and Hugo's [powerful sorting methods][lists]. Let's assume you have a list page at `example.com/articles`. You have 10 articles, but you want your templating for the [list/section page][] to show only two rows: 34 35 1. The top row is titled "Featured" and shows only the most recently published article (i.e. by `publishdate` in the content files' front matter). 36 2. The second row is titled "Recent Articles" and shows only the 2nd- to 4th-most recently published articles. 37 38 {{< code file="layouts/section/articles.html" download="articles.html" >}} 39 {{ define "main" }} 40 <section class="row featured-article"> 41 <h2>Featured Article</h2> 42 {{ range first 1 .Pages.ByPublishDate.Reverse }} 43 <header> 44 <h3><a href="{{.Permalink}}">{{.Title}}</a></h3> 45 </header> 46 <p>{{.Description}}</p> 47 {{ end }} 48 </section> 49 <div class="row recent-articles"> 50 <h2>Recent Articles</h2> 51 {{ range first 3 (after 1 .Pages.ByPublishDate.Reverse) }} 52 <section class="recent-article"> 53 <header> 54 <h3><a href="{{.Permalink}}">{{.Title}}</a></h3> 55 </header> 56 <p>{{.Description}}</p> 57 </section> 58 {{ end }} 59 </div> 60 {{ end }} 61 {{< /code >}} 62 63 [`first` function]: /functions/first/ 64 [list/section page]: /templates/section-templates/ 65 [lists]: /lists/ 66 [slice]: /functions/slice/