ref: 34fe5cd34f7e95e9566d60dbc333572c17e3957f
parent: a00edff5b1e1b2d230808c14993f5f5cb1cfb0ec
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Sep 7 18:03:09 EDT 2016
tpl: Fix echoParam Fixes #2406
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -1178,6 +1178,12 @@
}
}
+ avv, isNil = indirect(avv)
+
+ if isNil {
+ return ""
+ }
+
if avv.IsValid() {
switch avv.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
--- a/tpl/template_funcs_test.go
+++ b/tpl/template_funcs_test.go
@@ -94,6 +94,7 @@
dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}
delimit: {{ delimit (slice "A" "B" "C") ", " " and " }}
div: {{div 6 3}}
+echoParam: {{ echoParam .Params "langCode" }}
emojify: {{ "I :heart: Hugo" | emojify }}
eq: {{ if eq .Section "blog" }}current{{ end }}
findRE: {{ findRE "[G|g]o" "Hugo is a static side generator written in Go." 1 }}
@@ -162,6 +163,7 @@
dateFormat: Wednesday, Jan 21, 2015
delimit: A, B and C
div: 2
+echoParam: en
emojify: I ❤️ Hugo
eq: current
findRE: [go]
@@ -223,10 +225,12 @@
var data struct {
Title string
Section string
+ Params map[string]interface{}
}
data.Title = "**BatMan**"
data.Section = "blog"
+ data.Params = map[string]interface{}{"langCode": "en"}
viper.Set("baseURL", "http://mysite.com/hugo/")