Skip to content

Commit

Permalink
Added Templ tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Jan 25, 2024
1 parent 8019304 commit 374d08b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
7 changes: 7 additions & 0 deletions documentation/docs/tutorials/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "🍰 Tutorials",
"position": 3,
"link": {
"type": "generated-index"
}
}
32 changes: 32 additions & 0 deletions documentation/docs/tutorials/templ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Templ

Fuego supports templating with [Templ](https://github.com/a-h/templ).

Simply return a Templ component from your handler, with the `fuego.Templ` return type.

Example from [a recipe app](https://github.com/go-fuego/fuego/tree/main/examples/simple-crud):

```go
// highlight-next-line
func (rs Ressource) adminIngredients(c fuego.Ctx[any]) (fuego.Templ, 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
}
```
5 changes: 3 additions & 2 deletions documentation/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type * as Preset from "@docusaurus/preset-classic";

const config: Config = {
title: "Fuego",
tagline: "The blazing fast Go framework",
tagline: "The framework for busy Go developers",
favicon: "img/fuego.ico",

// Set the production url of your site here
Expand Down Expand Up @@ -54,7 +54,7 @@ const config: Config = {

themeConfig: {
// Replace with your project's social card
image: "img/docusaurus-social-card.jpg",
image: "img/fuego.png",
navbar: {
title: "Fuego",
logo: {
Expand Down Expand Up @@ -119,6 +119,7 @@ const config: Config = {
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
defaultLanguage: "go",
},
} satisfies Preset.ThemeConfig,
};
Expand Down

0 comments on commit 374d08b

Please sign in to comment.