mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Add shortcode IsNamedParams property
It would be helpful to know whether a shortcode was called with positional or named parameters. This commit adds a boolean `IsNamedParams` property to the `ShortcodeWithPage` struct.
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
3d09de8910
commit
fde47c5eb9
@@ -31,9 +31,10 @@ import (
|
||||
)
|
||||
|
||||
type ShortcodeWithPage struct {
|
||||
Params interface{}
|
||||
Inner template.HTML
|
||||
Page *Page
|
||||
Params interface{}
|
||||
Inner template.HTML
|
||||
Page *Page
|
||||
IsNamedParams bool
|
||||
}
|
||||
|
||||
func (scp *ShortcodeWithPage) Ref(ref string) (string, error) {
|
||||
@@ -189,7 +190,6 @@ const innerCleanupRegexp = `\A<p>(.*)</p>\n\z`
|
||||
const innerCleanupExpand = "$1"
|
||||
|
||||
func renderShortcode(sc shortcode, p *Page, t tpl.Template) string {
|
||||
var data = &ShortcodeWithPage{Params: sc.params, Page: p}
|
||||
tmpl := getShortcodeTemplate(sc.name, t)
|
||||
|
||||
if tmpl == nil {
|
||||
@@ -197,6 +197,11 @@ func renderShortcode(sc shortcode, p *Page, t tpl.Template) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
data := &ShortcodeWithPage{Params: sc.params, Page: p}
|
||||
if sc.params != nil {
|
||||
data.IsNamedParams = reflect.TypeOf(sc.params).Kind() == reflect.Map
|
||||
}
|
||||
|
||||
if len(sc.inner) > 0 {
|
||||
var inner string
|
||||
for _, innerData := range sc.inner {
|
||||
|
Reference in New Issue
Block a user