summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-05-21 17:47:52 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-05-21 18:52:13 +0200
commit2f17f9378ad96c4a9f6d7d24b0776ed3a25a08a3 (patch)
tree5b7885e08af3628869cbe93088923b29e81ce6a3 /hugolib/shortcode.go
parent0a7027e2a87283743d5310b74e18666e4a64d3e1 (diff)
Do not return error on .Get "class" and vice versa in shortcodes
The current error handling makes parameter checking in shortcodes too verbose for no good reason. Fixes #4745
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r--hugolib/shortcode.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index b82c1b6c2..937a90956 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -85,7 +85,10 @@ func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
switch key.(type) {
case int64, int32, int16, int8, int:
if reflect.TypeOf(scp.Params).Kind() == reflect.Map {
- return "error: cannot access named params by position"
+ // We treat this as a non error, so people can do similar to
+ // {{ $myParam := .Get "myParam" | default .Get 0 }}
+ // Without having to do additional checks.
+ return nil
} else if reflect.TypeOf(scp.Params).Kind() == reflect.Slice {
idx := int(reflect.ValueOf(key).Int())
ln := reflect.ValueOf(scp.Params).Len()
@@ -101,10 +104,10 @@ func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
return ""
}
} else if reflect.TypeOf(scp.Params).Kind() == reflect.Slice {
- if reflect.ValueOf(scp.Params).Len() == 1 && reflect.ValueOf(scp.Params).Index(0).String() == "" {
- return nil
- }
- return "error: cannot access positional params by string name"
+ // We treat this as a non error, so people can do similar to
+ // {{ $myParam := .Get "myParam" | default .Get 0 }}
+ // Without having to do additional checks.
+ return nil
}
}