Skip to content

Commit

Permalink
docs: Gomponents support
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Feb 12, 2024
1 parent 2fb1ffe commit 48b2960
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions documentation/docs/tutorials/rendering/gomponents.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,30 @@
Fuego supports rendering HTML templates with [Gomponents](https://github.com/maragudk/gomponents).

Just use the `fuego.Gomponent` type as a return type for your handler, and return the gomponent.

```go
// highlight-next-line
func (rs Ressource) adminIngredients(c fuego.ContextNoBody) (fuego.Gomponent, error) {
searchParams := components.SearchParams{
Name: c.QueryParam("name"),
PerPage: c.QueryParamInt("perPage", 20),
Page: c.QueryParamInt("page", 1),
URL: "/admin/ingredients",
Lang: c.MainLang(),
}

ingredients, err := rs.IngredientsQueries.SearchIngredients(c.Context(), store.SearchIngredientsParams{
Name: "%" + searchParams.Name + "%",
Limit: int64(searchParams.PerPage),
Offset: int64(searchParams.Page-1) * int64(searchParams.PerPage),
})
if err != nil {
return nil, err
}

// highlight-next-line
return admin.IngredientList(ingredients, searchParams), nil
}
```

Note that the `fuego.Gomponent` type is a simple alias for `fuego.Renderer` : any type that implements the `Render(io.Writer) error` method can be used as a return type for a handler.

0 comments on commit 48b2960

Please sign in to comment.