Skip to content

Commit

Permalink
docs: update methods example (#267)
Browse files Browse the repository at this point in the history
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
  • Loading branch information
af-md and a-h authored Oct 31, 2023
1 parent 9034035 commit df1983c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/docs/04-core-concepts/01-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,31 @@ func main() {
This code is unsafe! In code-only components, you're responsible for escaping the HTML content yourself, e.g. with the `templ.EscapeString` function.
:::

## Method components

templ components can be returned from methods (functions attached to types).

Go code:

```
package main
type Data struct {
message string
}
templ (d Data) Method() {
<div>{ d.message }</div>
}
func main() {
d := Data{
message: "You can implement methods on a type.",
}
d.Method().Render(context.Background(), os.Stdout)
}
```




0 comments on commit df1983c

Please # to comment.