mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	@@ -58,6 +58,7 @@ type ShortcodeWithPage struct {
 | 
			
		||||
	Inner         template.HTML
 | 
			
		||||
	Page          *PageWithoutContent
 | 
			
		||||
	Parent        *ShortcodeWithPage
 | 
			
		||||
	Name          string
 | 
			
		||||
	IsNamedParams bool
 | 
			
		||||
 | 
			
		||||
	// Zero-based ordinal in relation to its parent. If the parent is the page itself,
 | 
			
		||||
@@ -401,7 +402,7 @@ func renderShortcode(
 | 
			
		||||
		return "", nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	data := &ShortcodeWithPage{Ordinal: sc.ordinal, posOffset: sc.pos, Params: sc.params, Page: p, Parent: parent}
 | 
			
		||||
	data := &ShortcodeWithPage{Ordinal: sc.ordinal, posOffset: sc.pos, Params: sc.params, Page: p, Parent: parent, Name: sc.name}
 | 
			
		||||
	if sc.params != nil {
 | 
			
		||||
		data.IsNamedParams = reflect.TypeOf(sc.params).Kind() == reflect.Map
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1027,7 +1027,7 @@ ordinal: 4 scratch ordinal: 5 scratch get ordinal: 4`)
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestShortcodePosition(t *testing.T) {
 | 
			
		||||
func TestShortcodeVariables(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
	assert := require.New(t)
 | 
			
		||||
 | 
			
		||||
@@ -1042,6 +1042,7 @@ title: "Hugo Rocks!"
 | 
			
		||||
   {{< s1 >}}
 | 
			
		||||
 | 
			
		||||
`).WithTemplatesAdded("layouts/shortcodes/s1.html", `
 | 
			
		||||
Name: {{ .Name }}
 | 
			
		||||
{{ with .Position }}
 | 
			
		||||
File: {{ .Filename }}
 | 
			
		||||
Offset: {{ .Offset }}
 | 
			
		||||
@@ -1059,6 +1060,7 @@ String: {{ . | safeHTML }}
 | 
			
		||||
		filepath.FromSlash("File: content/page.md"),
 | 
			
		||||
		"Line: 7", "Column: 4", "Offset: 40",
 | 
			
		||||
		filepath.FromSlash("String: \"content/page.md:7:4\""),
 | 
			
		||||
		"Name: s1",
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user