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

rendering template multiple times fails #11

Closed
toomasj opened this issue Jun 12, 2020 · 0 comments · Fixed by Fenny/template#3 or #13
Closed

rendering template multiple times fails #11

toomasj opened this issue Jun 12, 2020 · 0 comments · Fixed by Fenny/template#3 or #13
Labels
☢️ Bug Something isn't working

Comments

@toomasj
Copy link
Contributor

toomasj commented Jun 12, 2020

When html engine has Reload(true), then rendering multiple times, it fails with 'html/template: cannot Parse after Execute'.

func Test_HTML_Render_Twice(t *testing.T) {
	engine := New("./views", ".html")
	engine.Reload(true)

	engine.AddFunc("isAdmin", func(user string) bool {
		return user == "admin"
	})
	if err := engine.Load(); err != nil {
		t.Fatalf("load: %v\n", err)
	}

	var buf, buf2 bytes.Buffer
	engine.Render(&buf, "index", map[string]interface{}{
		"Title": "Hello, World!",
	}, "layouts/main")

	err := engine.Render(&buf2, "index", map[string]interface{}{
		"Title": "Hello, World!",
	}, "layouts/main")

	if err != nil {
		fmt.Println(err.Error())
	}

	expect := `<!DOCTYPE html><html><head><title>Main</title></head><body><h2>Header</h2><h1>Hello, World!</h1><h2>Footer</h2></body></html>`
	result := trim(buf2.String())
	if expect != result {
		t.Fatalf("Expected:\n%s\nResult:\n%s\n", expect, result)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working
Projects
None yet
2 participants