Reload views?
I've beein going through the Fiber code and stumbled upon the following line:
https://github.com/gofiber/fiber/blob/aaad4cf56e004d1453e41f766db74afe14739214/app.go#L1226C30-L1226C34
I was wondering if there are any side-effects that would prevent a call to app.config.Views.Load() from being made public via an app.ReloadViews() wrapper (or similar)?
The reason I'm asking is because I'm looking for a way to reload the whole views directory from disk without restarting the whole app.
Wow, that was quick! Thank you @ReneWerner87 and @gaby. :-)
I have tested this implementation, however, it doesn't appear to be working in my case. I have detailed the issue here.
@mrusme I'm not sure if that's the correct way to use it. Can you try adding a handler /reload and calling it via fsnotify then in that handler run c.app.ReloadViews() ?
Actually what you have makes sense, I'm just not sure if you have a pointer to app or not from the example you provided.
Also, try visiting the site in a private tab, maybe the browser is caching the html
Can you try adding a handler
/reloadand calling it via fsnotify then in that handler runc.app.ReloadViews()?
Good suggestion! I added the following to my existing handler:
func (r *Route) Index(c fiber.Ctx) error {
err := c.App().ReloadViews()
r.Runtime.Error("error", err)
return c.Render("views/root", fiber.Map{
"Page": page.New(r.Runtime, c, "Root"),
}, "views/layouts/base")
}
I am updating views/root.html and keep refreshing that route. Sadly the content doesn't change. I ruled out browser side caching as well. The Error output shows that err is null all the time.
@mrusme Thanks, will investigate