Description: go text/template is a package library that provides a way to format text using templates. It allows you to create templates for text and then fill those templates with values to create the final output.
Description: This example creates a new template named "test" and then parse the text "Hello, {{.}}" as the template. The "{{.}}" is a placeholder for the value that we will provide when we execute the template. In this case, we provide the value "World" and the output will be "Hello, World".
Example 2:
import ( "os" "text/template" )
type Person struct { Name string Age int }
func main() { tpl, _ := template.New("test").Parse("My name is {{.Name}} and I am {{.Age}} years old.") p := Person{Name: "John", Age: 30} tpl.Execute(os.Stdout, p) }
Description: This example creates a new template named "test" and then parse the text "My name is {{.Name}} and I am {{.Age}} years old." as the template. This template has two placeholders: {{.Name}} and {{.Age}}. We create a struct named Person with two fields: Name and Age. Then we fill those fields with values (John and 30 respectively) and pass the entire struct to the template. When we execute the template, it will replace {{.Name}} with John and {{.Age}} with 30, resulting in the output "My name is John and I am 30 years old."
Golang Template.Name - 15 examples found. These are the top rated real world Golang examples of text/template.Template.Name extracted from open source projects. You can rate examples to help us improve the quality of examples.