-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🔥 RENDER template files from embedded resources #422
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Hi @JohannesKaufmann, this should be possible.
I will play with this today, I will keep you posted 👍 |
@JohannesKaufmann, we are currently adding engine := html.NewFileSystem(http.Dir("./views"), ".html") Thanks to @arsmn we got a neat walk function for embedded file systems. We are 50% done https://github.com/Fenny/template/blob/master/html/html_test.go#L103 and I will notify you when we tag a release 👍 |
@JohannesKaufmann if you update https://github.com/gofiber/template to the latest version, you can use the pkgerhttps://github.com/markbates/pkger package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/template/html"
"github.com/markbates/pkger"
)
func main() {
engine := html.NewFileSystem(pkger.Dir("/views"), ".html")
app := fiber.New(&fiber.Settings{
Views: engine,
})
// ...
} packrhttps://github.com/gobuffalo/packr package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/template/html"
"github.com/gobuffalo/packr/v2"
)
func main() {
engine := html.NewFileSystem(packr.New("Templates", "/views"), ".html")
app := fiber.New(&fiber.Settings{
Views: engine,
})
// ...
} go.ricehttps://github.com/GeertJohan/go.rice package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/template/html"
"github.com/GeertJohan/go.rice"
)
func main() {
engine := html.NewFileSystem(rice.MustFindBox("views").HTTPBox(), ".html")
app := fiber.New(&fiber.Settings{
Views: engine,
})
// ...
} fileb0xhttps://github.com/UnnoTed/fileb0x package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/template/html"
// your generated package
"github.com/<user>/<repo>/static"
)
func main() {
engine := html.NewFileSystem(static.HTTP, ".html")
app := fiber.New(&fiber.Settings{
Views: engine,
})
// ...
} |
@Fenny great, that new engine looks amazing. This also solves some problems that I encountered in the meantime with the views. But this is now solved with P.S.: I'm currently evaluating different strategies for hot reloading html, css and js files for rendered websites. That makes the feedback loop alot faster and plays nicely with air. I will let you know in the coming days how the middleware (using lrserver) could look like. I'm also happy to do a PR then... |
Is your feature request related to a problem?
I want to render templates on the server, using embedded files from
pkger
.Describe the solution you'd like
It would be great if one could pass in a
http.FileSystem
instead of thestring
.Additional context
I am already using embed to serve static files (like css) and it works great! 🥳
similar to #209 and #375
P.S.: I would mention the embed middleware in the docs (with the tag "FileSystem" so that you can find it in the search) and mention it in the static-files section.
I was kind of disappointed - at first - that you didn't support that. Many routers don't have good support of embed, if at all. For example, echo has marked it as wont-fix 😢.
The text was updated successfully, but these errors were encountered: