Last active
September 17, 2016 03:07
-
-
Save asit-dhal/8b2f7ce23ad7ec3f75984cac483a5f6a to your computer and use it in GitHub Desktop.
template action demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template A includes Template B | |
Template B | |
Template A ends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"html/template" | |
"os" | |
"fmt" | |
) | |
var templateDemo = | |
` | |
{{ define "a" }} | |
Template A includes Template B | |
{{ template "b" .}} | |
Template A ends | |
{{ end }} | |
{{define "b"}} | |
Template B | |
{{end}} | |
` | |
func main() { | |
var err error | |
t := template.New("templateActionDemo") | |
t, err = t.Parse(templateDemo) | |
if err != nil { | |
fmt.Println("parsing failed: %s", err) | |
} | |
err = t.ExecuteTemplate(os.Stdout, "a", nil) | |
if err != nil { | |
fmt.Println("execution failed: %s", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment