Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-07 22:03:09 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-07 22:03:09 +0300
commit34fe5cd34f7e95e9566d60dbc333572c17e3957f (patch)
tree667cb548672eb07e7a980c2ecb468f630e7f01d9 /tpl
parenta00edff5b1e1b2d230808c14993f5f5cb1cfb0ec (diff)
tpl: Fix echoParam
Fixes #2406
Diffstat (limited to 'tpl')
-rw-r--r--tpl/template_funcs.go6
-rw-r--r--tpl/template_funcs_test.go4
2 files changed, 10 insertions, 0 deletions
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 "<p>Blockhead</p>\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: <p>Blockhead</p>
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/")