- Passed the layout when render
1engine := html.New("./views", ".html")
2
3app := fiber.New(fiber.Config{
4 Views: engine,
5})
6
7app.Get("/", func(c *fiber.Ctx*) error {
8 return c.Render(
9 "html_file_to_render", // ex: index -> /view/index.html
10 nil, // fiber data
11 "layout/main", // path: /view/layout/main
12 )
13})
- Set default layout to the engine
1engine := html.New("./views", ".html")
2
3app := fiber.New(fiber.Config{
4 Views: engine,
5 ViewsLayout: "layouts/main", // pass the layout here
6})
7
8app.Get("/", func(c *fiber.Ctx*) error {
9 return c.Render(
10 "html_file_to_render", // ex: index -> /view/index.html
11 nil, // fiber data
12 ) // it will rendered with the layout
13})
- Exclude the layout when the layout in engine is set
1engine := html.New("./views", ".html")
2
3app := fiber.New(fiber.Config{
4 Views: engine,
5 ViewsLayout: "layouts/main", // pass the layout here
6})
7
8app.Get("/", func(c *fiber.Ctx*) error {
9 return c.Render(
10 "html_file_to_render", // ex: index -> /view/index.html
11 nil, // fiber data
12 "". // add empty string to exclude the layout
13 ) // html_file_to_render will rendered without the layout
14})