Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct's method calling not working again? #227

Closed
shawnye opened this issue Feb 18, 2020 · 1 comment
Closed

Struct's method calling not working again? #227

shawnye opened this issue Feb 18, 2020 · 1 comment

Comments

@shawnye
Copy link

shawnye commented Feb 18, 2020

I've studied #8 then tried to run go run main.go, and got nothing printed , could you help me what's wrong with it, thank you!

//main.go
package main

import (
	"github.com/flosch/pongo2"
)

func main() {
	ctx := map[string]interface{}{
		"Test": Test{Name: "My Test"},
	}
 
	tpl, _ := pongo2.FromString("{{ Test.ShowName() }}")  //{{ Test.ShowName }} printed nothing also.

	out, _ := tpl.Execute(ctx)
 
	println(out)
}

type Test struct {
	Name string
}

 
func (t *Test) ShowName() *pongo2.Value {
	return pongo2.AsValue("ShowName")
}

@shawnye shawnye changed the title Struct method seems not work Struct's method calling not working again? Feb 18, 2020
@flosch
Copy link
Owner

flosch commented Feb 19, 2020

Have you checked the errors? Just return a string and try return "ShowName"

@flosch flosch closed this as completed Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants