Skip to content

Commit

Permalink
docs: update docs on template params
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Nov 2, 2023
1 parent 941644e commit 1a15a49
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/docs/03-syntax-and-usage/09-template-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,48 @@ func main() {
<p>Right contents</p>
</div>
```

You can pass `templ` components as parameters to other components within templates using standard Go function call syntax.

```templ
package main
templ layout(l, r templ.Component) {
<div id="left">
{! l }
</div>
<div id="right">
{! r }
</div>
}
templ paragraph(contents string) {
<p>{ contents }</p>
}
templ root() {
@layout(paragraph("Left contents"), paragraph("Right contents"))
}
```

```go title="main.go"
package main

import (
"context"
"os"
)

func main() {
root().Render(context.Background(), os.Stdout)
}
```

```html title="output"
<div id="left">
<p>Left contents</p>
</div>
<div id="right">
<p>Right contents</p>
</div>
```

0 comments on commit 1a15a49

Please sign in to comment.