From 34fe5cd34f7e95e9566d60dbc333572c17e3957f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 7 Sep 2016 22:03:09 +0300 Subject: [PATCH] tpl: Fix echoParam Fixes #2406 --- tpl/template_funcs.go | 6 ++++++ tpl/template_funcs_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go index 41e616b1b..b5b33bef0 100644 --- a/tpl/template_funcs.go +++ b/tpl/template_funcs.go @@ -1178,6 +1178,12 @@ func returnWhenSet(a, k interface{}) interface{} { } } + avv, isNil = indirect(avv) + + if isNil { + return "" + } + if avv.IsValid() { switch avv.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go index 3df38f380..eee4c36f2 100644 --- a/tpl/template_funcs_test.go +++ b/tpl/template_funcs_test.go @@ -94,6 +94,7 @@ chomp: {{chomp "

Blockhead

\n" }} 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 @@ chomp:

Blockhead

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 @@ urlize: bat-man 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/")