Let’s say I have
type Person struct {
Name string
}
func (p *Person) Label() string {
return "This is " + p.Name
}
How can I use this method from a html/template ? I would need something like this in my template:
{{ .Label() }}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just omit the parentheses and it should be fine. Example:
According to the documentation, you can call any method which returns one value (of any type) or two values if the second one is of type
error. In the later case,Executewill return that error if it is non-nil and stop the execution of the template.