From f76e482756007702c3f68b54750d97811a815a55 Mon Sep 17 00:00:00 2001 From: David Szabo Date: Tue, 27 Feb 2024 18:26:39 +0100 Subject: [PATCH 1/2] add inline component example and fix missing import --- docs/docs/04-core-concepts/01-components.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/docs/04-core-concepts/01-components.md b/docs/docs/04-core-concepts/01-components.md index 442009e0..8bd26994 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,25 @@ func main() { } ``` +It is also possible to initlize 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() +} +``` From b11ec264462f9da0bbaf7a43d03e7d27d7f18b74 Mon Sep 17 00:00:00 2001 From: joerdav Date: Fri, 1 Mar 2024 10:59:28 +0000 Subject: [PATCH 2/2] chore: nits --- docs/docs/04-core-concepts/01-components.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/docs/04-core-concepts/01-components.md b/docs/docs/04-core-concepts/01-components.md index 8bd26994..159534c4 100644 --- a/docs/docs/04-core-concepts/01-components.md +++ b/docs/docs/04-core-concepts/01-components.md @@ -84,7 +84,7 @@ func main() { } ``` -It is also possible to initlize a struct and call it's component method inline. +It is also possible to initialize a struct and call it's component method inline. ```templ package main @@ -100,9 +100,15 @@ templ (d Data) Method() { } templ Message() { - @Data{ - message: "You can implement methods on a type.", - }.Method() +
+ @Data{ + message: "You can implement methods on a type.", + }.Method() +
+} + +func main() { + Message().Render(context.Background(), os.Stdout) } ```