Adding documentation about 'where' and cleaning up docs around first.
authorspf13 <steve.francia@gmail.com>
Sat, 30 Aug 2014 04:57:38 +0000 (00:57 -0400)
committerspf13 <steve.francia@gmail.com>
Sat, 30 Aug 2014 04:57:38 +0000 (00:57 -0400)
docs/content/templates/content.md
docs/content/templates/functions.md
docs/content/templates/list.md

index cecc8b66558e2a0cb57a6486277b8bde46ab9306..30778735aae272bcf023b9aa4596e10f7e4eb5c2 100644 (file)
@@ -2,7 +2,7 @@
 aliases:
 - /layout/functions/
 date: 2013-07-01
-linktitle: Single
+linktitle: Single Content
 menu:
   main:
     parent: layout
index a37c60510a4c572f6786777a1245a9ed5f1ed2b7..154a80120964b4b5794e2098a0b7f10762ba8ffe 100644 (file)
@@ -38,11 +38,32 @@ eg. {{echoParam .Params "project_url" }}
 ### first
 Slices an array to only the first X elements.
 
+Works on [lists](/templates/list/), [taxonomies](/taxonomies/displaying/), [terms](/templates/terms/), [groups](/templates/list/)
+
 eg.
     {{ range first 10 .Data.Pages }}
         {{ .Render "summary"}}
     {{ end }}
 
+### where
+Filters an array to only elements containing a matching value for a given field.
+
+Works on [lists](/templates/list/), [taxonomies](/taxonomies/displaying/), [terms](/templates/terms/), [groups](/templates/list/)
+
+eg.
+
+    {{ range where .Data.Pages "Section" "post" }}
+       {{ .Content}}
+    {{ end }}
+
+*where and first can be stacked*
+
+eg.
+
+    {{ range first 5 (where .Data.Pages "Section" "post") }}
+       {{ .Content}}
+    {{ end }}
+
 
 ## Math
 
index 5b4026bfaee00113cff0ee7b24738ba9425c3834..2bc615a2a0c4b9dcca97415443947be6a5faf28a 100644 (file)
@@ -2,7 +2,7 @@
 aliases:
 - /layout/indexes/
 date: 2013-07-01
-linktitle: List
+linktitle: List of Content
 menu:
   main:
     parent: layout
@@ -296,3 +296,43 @@ within each group in alphabetical order by title.
         {{ end }}
     </ul>
     {{ end }}
+
+## Filtering & Limiting Content
+
+Sometimes you only want to list a subset of the available content. A common
+request is to only display “Posts” on the homepage. Using the `where` function
+you can do just that.
+
+### First 
+
+`first` works like the limit keyword in SQL. It reduces the array to only the
+first X elements. It takes the array and number of elements as input.
+
+    {{ range first 10 .Data.Pages }}
+        {{ .Render "summary"}}
+    {{ end }}
+
+### Where
+
+`where` works in a similar manner to the where keyword in SQL. It selects all
+elements of the slice that match the provided field and value. It takes three
+arguments 'array or slice of maps or structs', 'key or field name' and 'match
+value'
+
+    {{ range where .Data.Pages "Section" "post" }}
+       {{ .Content}}
+    {{ end }}
+
+### First & Where Together
+
+Using both together can be very powerful.
+
+    {{ range first 5 (where .Data.Pages "Section" "post") }}
+       {{ .Content}}
+    {{ end }}
+
+If `where` or `first` receives invalid input or a field name that doesn’t exist they will provide an error and stop site generation.
+
+These are both template functions and work on not only
+[lists](/templates/list/), but [taxonomies](/taxonomies/displaying/),
+[terms](/templates/terms/) and [groups](/templates/list/).