From 0ac072ffd01315635994da02d59fcbd6ddcdacae Mon Sep 17 00:00:00 2001 From: David Szabo Date: Fri, 1 Mar 2024 12:00:46 +0100 Subject: [PATCH] chore(docs): add inline component example (#565) Co-authored-by: joerdav --- docs/docs/04-core-concepts/01-components.md | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/docs/04-core-concepts/01-components.md b/docs/docs/04-core-concepts/01-components.md index 442009e05..159534c45 100644 --- a/docs/docs/04-core-concepts/01-components.md +++ b/docs/docs/04-core-concepts/01-components.md @@ -66,6 +66,8 @@ Go code: ```templ package main +import "os" + type Data struct { message string } @@ -82,6 +84,31 @@ func main() { } ``` +It is also possible to initialize a struct and call it's component method inline. +```templ +package main +import "os" + +type Data struct { + message string +} + +templ (d Data) Method() { +
{ d.message }
+} + +templ Message() { +
+ @Data{ + message: "You can implement methods on a type.", + }.Method() +
+} + +func main() { + Message().Render(context.Background(), os.Stdout) +} +```