mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
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
This commit is contained in:
parent
0a7027e2a8
commit
2f17f9378a
2 changed files with 11 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue