shithub: hugo

Download patch

ref: cabc6b31866e3bb86759f6615a83cec4c3610e82
parent: 707d3cf13777a23ba6ab39d8d00d41f02b8c6a68
author: Nishanth Shanmugham <[email protected]>
date: Sat Dec 31 14:50:46 EST 2016

tpl: Add now function

Add a now template function that returns the current time as time.Time.
Also, update related docs.

--- a/docs/content/templates/functions.md
+++ b/docs/content/templates/functions.md
@@ -804,6 +804,10 @@
 * `{{ (time "2016-05-28").YearDay }}` → 149
 * `{{ mul 1000 (time "2016-05-28T10:30:00.00+10:00").Unix }}` → 1464395400000 (Unix time in milliseconds)
 
+### now
+
+`now` returns the current local time as a [`time.Time`](https://godoc.org/time#Time).
+
 ## URLs
 ### absLangURL, relLangURL
 These are similar to the `absURL` and `relURL` relatives below, but will add the correct language prefix when the site is configured with more than one language.
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -2146,6 +2146,7 @@
 		"modBool":       modBool,
 		"mul":           func(a, b interface{}) (interface{}, error) { return helpers.DoArithmetic(a, b, '*') },
 		"ne":            ne,
+		"now":           func() time.Time { return time.Now() },
 		"partial":       partial,
 		"partialCached": partialCached,
 		"plainify":      plainify,