Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): add inline component example #565

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 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,25 @@ func main() {
}
```

It is also possible to initlize a struct and call it's component method inline.
joerdav marked this conversation as resolved.
Show resolved Hide resolved

```templ
package main

import "os"

type Data struct {
message string
}

templ (d Data) Method() {
<div>{ d.message }</div>
}

templ Message() {
@Data{
message: "You can implement methods on a type.",
}.Method()
}
```