Skip to content

Commit

Permalink
chore(docs): add inline component example (#565)
Browse files Browse the repository at this point in the history
Co-authored-by: joerdav <[email protected]>
  • Loading branch information
Ra0k and joerdav authored Mar 1, 2024
1 parent edb6b55 commit 0ac072f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/docs/04-core-concepts/01-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Go code:
```templ
package main
import "os"
type Data struct {
message string
}
Expand All @@ -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() {
<div>{ d.message }</div>
}
templ Message() {
<div>
@Data{
message: "You can implement methods on a type.",
}.Method()
</div>
}
func main() {
Message().Render(context.Background(), os.Stdout)
}
```

0 comments on commit 0ac072f

Please sign in to comment.