You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Render` method is linked to the [**ctx.Render\(\)**](../api/ctx.md#render) function that accepts a template name and binding data.
64
+
:::
65
+
66
+
67
+
## Rendering Templates
68
+
69
+
Once an engine is set up, a route handler can call the [**ctx.Render\(\)**](../api/ctx.md#render) function with a template name and binded data to send the rendered template.
By default, [**ctx.Render\(\)**](../api/ctx.md#render) searches for the template name in the `ViewsLayout` path. To override this setting, provide the path(s) in the `layouts` argument.
77
+
:::
78
+
79
+
80
+
<Tabs>
81
+
82
+
<TabItem value="example" label="Example">
83
+
84
+
```go
85
+
app.Get("/", func(c *fiber.Ctx) error {
86
+
return c.Render("index", fiber.Map{
87
+
"Title": "Hello, World!",
88
+
})
89
+
90
+
})
91
+
```
92
+
24
93
</TabItem>
94
+
95
+
<TabItemvalue="index"label="layouts/index.html">
96
+
97
+
```html
98
+
<!DOCTYPE html>
99
+
<html>
100
+
<body>
101
+
<h1>{{.Title}}</h1>
102
+
</body>
103
+
</html>
104
+
```
105
+
106
+
</TabItem>
107
+
25
108
</Tabs>
26
109
27
-
`Views` interface contains a `Load` and `Render` method, `Load` is executed by Fiber on app initialization to load/parse the templates.
110
+
:::caution
111
+
If the Fiber config option `PassLocalsToViews` is enabled, then all locals set using `ctx.Locals(key, value)` will be passed to the template. It is important to avoid clashing keys when using this setting.
112
+
:::
113
+
114
+
## Advanced Templating
115
+
116
+
### Custom Functions
117
+
118
+
Fiber supports adding custom functions to templates.
The `Render` method is linked to the [**ctx.Render\(\)**](../api/ctx.md#render) function that accepts a template name and binding data. It will use global layout if layout is not being defined in `Render` function.
39
-
If the Fiber config option `PassLocalsToViews` is enabled, then all locals set using `ctx.Locals(key, value)` will be passed to the template.
0 commit comments