shithub: hugo

Download patch

ref: 275e1c0d234135a9938ecfc5b2fab861fc5170df
parent: becd4fe337822b450ac88005ccec8414de8351a0
author: Alex Dunn <[email protected]>
date: Wed Sep 10 05:42:58 EDT 2014

more examples and explanation of go templating

Emphasizing to people (like me) who aren't familiar with Go that just because something's not mentioned in the Hugo docs doesn't mean it's not possible

--- a/docs/content/templates/functions.md
+++ b/docs/content/templates/functions.md
@@ -20,7 +20,9 @@
 Go templates are lightweight but extensible. Hugo has added the following
 functions to the basic template logic.
 
-Go documentation for the built-in functions can be found [here](http://golang.org/pkg/text/template/)
+(Go itself supplies built-in functions, including comparison operators
+and other basic tools; these are listed in the
+[Go template documentation](http://golang.org/pkg/text/template/#hdr-Functions).)
 
 ## General
 
--- a/docs/content/templates/go-templates.md
+++ b/docs/content/templates/go-templates.md
@@ -20,7 +20,7 @@
 similarities in Go templates.
 
 This document is a brief primer on using Go templates. The [Go docs][gohtmltemplate]
-provide more details.
+go into more depth and cover features that aren't mentioned here.
 
 ## Introduction to Go Templates
 
@@ -87,10 +87,17 @@
 followed by the required parameters separated by spaces. Template
 functions cannot be added without recompiling Hugo.
 
-**Example:**
+**Example 1: Adding numbers**
 
     {{ add 1 2 }}
 
+**Example 2: Comparing numbers**
+
+    {{ lt 1 2 }}
+
+(There are more boolean operators, detailed in the
+[template documentation](http://golang.org/pkg/text/template/#hdr-Functions).)
+
 ## Includes
 
 When including another template, you will pass to it the data it will be
@@ -142,7 +149,6 @@
 `if`, `else`, `with`, `or` & `and` provide the framework for handling conditional
 logic in Go Templates. Like `range`, each statement is closed with `end`.
 
-
 Go Templates treat the following values as false:
 
 * false
@@ -351,3 +357,23 @@
 
 [go]: http://golang.org/
 [gohtmltemplate]: http://golang.org/pkg/html/template/
+
+# Template example: Show only upcoming events
+
+Go allows you to do more than what's shown here.  Using Hugo's
+[`where`](/templates/functions/#toc_4) function and Go built-ins, we can list
+only the items from `content/events/` whose date (set in the front matter) is in
+the future:
+
+    <h4>Upcoming Events</h4>
+    <ul class="upcoming-events">
+    {{ range where .Data.Pages.ByDate "Section" "events" }}
+      {{ if ge .Date.Unix .Now.Unix }}
+        <li><span class="event-type">{{ .Type | title }} —</span>
+          {{ .Title }}
+          on <span class="event-date">
+          {{ .Date.Format "2 January at 3:04pm" }}</span>
+          at {{ .Params.place }}
+        </li>
+      {{ end }}
+    {{ end }}