feat: add render doc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d89541a762
commit
6404e00cb5
1 changed files with 40 additions and 0 deletions
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
linkTitle: Rendering
|
||||
title: Rendering
|
||||
weight: 6
|
||||
---
|
||||
|
||||
**go-form** allows you to render a form using Go's built-in template engine.
|
||||
Here is a simple example that displays a form:
|
||||
|
||||
```golang
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
myForm := form.NewForm(...)
|
||||
|
||||
render := theme.NewRenderer(theme.Html5)
|
||||
tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(`
|
||||
<html>
|
||||
<head>
|
||||
<title>My form</title>
|
||||
</head>
|
||||
<body>
|
||||
{{ form .Form }}
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
tpl.Execute(w, map[string]any{
|
||||
"Form": myForm,
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Other helper functions are available to render specific parts of the form:
|
||||
|
||||
- `form_errors`: displays the form's global errors
|
||||
- `form_row` : renders the label, errors, and widget of a field
|
||||
- `form_label`: renders only the label of a field
|
||||
- `form_widget`: renders only the widget of a field
|
||||
- `form_widget_errors`: renders only the errors of a specific field
|
||||
Loading…
Add table
Add a link
Reference in a new issue