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

views template error #5

Closed
xiake999 opened this issue Jul 14, 2017 · 2 comments
Closed

views template error #5

xiake999 opened this issue Jul 14, 2017 · 2 comments

Comments

@xiake999
Copy link

xiake999 commented Jul 14, 2017

--views
   --home
      --header.html
   --index.html

index.html
{{template "home/header.html" .}}

head.html
test

html/template:index.html:5:11: no such template "home/header.html"

@xthezealot
Copy link
Member

xthezealot commented Jul 14, 2017

Yes, because the template function receives a template name, not a file name (see GoDoc of standard template package):

In index.html:

{{define "index"}}
	{{template "homeHeader" .}}
{{end}}

In head.html:

{{define "homeHeader"}}
	test
{{end}}

And to execute the index template:

app.Get("/", func(c *app.Context) {
	c.View("index")
})

The structure of the views directory has no importance: all files are recursively parsed and treated like a single file. Putting templates in their own files only serves readability.

@xiake999
Copy link
Author

It has been settled, thank you

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