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

How can I access template files in assets_vfsdata.go #38

Closed
weiofcn opened this Issue Dec 4, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@weiofcn

weiofcn commented Dec 4, 2017

Hi, @shurcooL , this is a great package and its quite handy. I met a problem and did some research and still can't figure out by myself because I am a newbie of golang.

I have a file called index.templ which has already saved in assets_vfsdata.go, and there are also included many js and css files.

http.Handle("/", http.StripPrefix("/", fs)) uesed to satisfy my most requirements, but now I write some templates for my html pages, then I have no idea how to return a html page to http server after parsing my template and data.

It seems I have to retrieve the compressedContent in the map and replace it by using template.New("").Parse() before start http server.(this may not right)

So, is there a easier(or right) way to access partial template files and make them works like template.ParseFiles("./index.templ").

Thanks for the help.

@cryptix

This comment has been minimized.

Show comment
Hide comment
@cryptix

cryptix Dec 4, 2017

Have you seen github.com/shurcooL/httpfs/html/vfstemplate? It's like a drop-in replacement for html/template which works on http.Filesystems. I think it should cover your needs.

cryptix commented Dec 4, 2017

Have you seen github.com/shurcooL/httpfs/html/vfstemplate? It's like a drop-in replacement for html/template which works on http.Filesystems. I think it should cover your needs.

@dmitshur

This comment has been minimized.

Show comment
Hide comment
@dmitshur

dmitshur Dec 4, 2017

Member

@cryptix's suggestion is right on. Package github.com/shurcooL/httpfs/html/vfstemplate is a convenient existing solution for what you're looking, I recommend it.

Also, note that you shouldn't have to use anything unexported from _vfsdata files. The generated assets are exposed via the http.FileSystem interface, and you should use its public method Open to access files. Files also implement GzipByter interface for direct access to compressed bytes.

Member

dmitshur commented Dec 4, 2017

@cryptix's suggestion is right on. Package github.com/shurcooL/httpfs/html/vfstemplate is a convenient existing solution for what you're looking, I recommend it.

Also, note that you shouldn't have to use anything unexported from _vfsdata files. The generated assets are exposed via the http.FileSystem interface, and you should use its public method Open to access files. Files also implement GzipByter interface for direct access to compressed bytes.

@dmitshur dmitshur added the question label Dec 4, 2017

@weiofcn

This comment has been minimized.

Show comment
Hide comment
@weiofcn

weiofcn Dec 5, 2017

@cryptix @shurcooL Thanks, that's what I need and it's so easy to use.

weiofcn commented Dec 5, 2017

@cryptix @shurcooL Thanks, that's what I need and it's so easy to use.

@weiofcn weiofcn closed this Dec 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment