diff --git a/documentation/docs/intro.md b/documentation/docs/index.md similarity index 100% rename from documentation/docs/intro.md rename to documentation/docs/index.md diff --git a/documentation/docs/tutorials/rendering/gomponents.md b/documentation/docs/tutorials/rendering/gomponents.md new file mode 100644 index 00000000..a1658f71 --- /dev/null +++ b/documentation/docs/tutorials/rendering/gomponents.md @@ -0,0 +1,5 @@ +# Gomponents + +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. diff --git a/documentation/docs/tutorials/rendering/index.md b/documentation/docs/tutorials/rendering/index.md new file mode 100644 index 00000000..b039a14f --- /dev/null +++ b/documentation/docs/tutorials/rendering/index.md @@ -0,0 +1,5 @@ +# HTML Rendering + +Fuego is not only capable to handle XML and JSON, it can also render HTML. + +It supports templating with [html/template](https://pkg.go.dev/html/template), [Templ](https://github.com/a-h/templ), and [Gomponents](https://github.com/maragudk/gomponents). diff --git a/documentation/docs/tutorials/rendering/std.md b/documentation/docs/tutorials/rendering/std.md new file mode 100644 index 00000000..f8ab0f26 --- /dev/null +++ b/documentation/docs/tutorials/rendering/std.md @@ -0,0 +1,28 @@ +--- +sidebar_position: 1 +--- + +# html/template + +Fuego supports rendering HTML templates with the [html/template](https://pkg.go.dev/html/template) package. + +Just use the `fuego.HTML` type as a return type for your handler, and return `c.Render()` with the template name and data. + +```go +// highlight-next-line +func (rs Ressource) unitPreselected(c fuego.Ctx[any]) (fuego.HTML, error) { + id := c.QueryParam("IngredientID") + + ingredient, err := rs.IngredientsQueries.GetIngredient(c.Context(), id) + if err != nil { + return "", err + } + +// highlight-start + return c.Render("preselected-unit.partial.html", fuego.H{ + "Units": types.UnitValues, + "SelectedUnit": ingredient.DefaultUnit, + }) +// highlight-end +} +``` diff --git a/documentation/docs/tutorials/templ.md b/documentation/docs/tutorials/rendering/templ.md similarity index 82% rename from documentation/docs/tutorials/templ.md rename to documentation/docs/tutorials/rendering/templ.md index 2f1c7d39..ac1cb1dc 100644 --- a/documentation/docs/tutorials/templ.md +++ b/documentation/docs/tutorials/rendering/templ.md @@ -30,3 +30,5 @@ func (rs Ressource) adminIngredients(c fuego.Ctx[any]) (fuego.Templ, error) { return admin.IngredientList(ingredients, searchParams), nil } ``` + +Note that the `fuego.Templ` type is a simple alias for `fuego.CtxRenderer` : any type that implements the `Render(context.Context, io.Writer) error` method can be used as a return type for a handler. diff --git a/documentation/docusaurus.config.ts b/documentation/docusaurus.config.ts index 379b0b82..d86b15dd 100644 --- a/documentation/docusaurus.config.ts +++ b/documentation/docusaurus.config.ts @@ -38,6 +38,7 @@ const config: Config = { // Please change this to your repo. // Remove this to remove the "edit this page" links. editUrl: "https://github.com/go-fuego/fuego", + sidebarCollapsed: false, }, blog: { showReadingTime: true, @@ -66,7 +67,12 @@ const config: Config = { type: "docSidebar", sidebarId: "tutorialSidebar", position: "left", - label: "Tutorial", + label: "Docs", + }, + { + href: "https://pkg.go.dev/github.com/go-fuego/fuego", + position: "left", + label: "Reference", }, { href: "https://github.com/go-fuego/fuego", @@ -82,8 +88,8 @@ const config: Config = { title: "Docs", items: [ { - label: "Tutorial", - to: "/docs/intro", + label: "Docs", + to: "/docs/", }, ], },