tpl: Fix echoParam - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 34fe5cd34f7e95e9566d60dbc333572c17e3957f
DIR parent a00edff5b1e1b2d230808c14993f5f5cb1cfb0ec
HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Wed, 7 Sep 2016 22:03:09 +0300
tpl: Fix echoParam
Fixes #2406
Diffstat:
M tpl/template_funcs.go | 6 ++++++
M tpl/template_funcs_test.go | 4 ++++
2 files changed, 10 insertions(+), 0 deletions(-)
---
DIR diff --git 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:
DIR diff --git 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/")