Dynamic Elements #827
Unanswered
ainsleyclark
asked this question in
Q&A
Replies: 1 comment
-
A little late to the show, but possibly something like this: package components
type ListProps struct {
Items []string
Ordered bool
}
func iif[T any](cond bool, t, f T) T {
if cond {
return t
}
return f
}
templ ul() {
<ul>
{ children... }
</ul>
}
templ ol() {
<ol>
{ children... }
</ol>
}
templ List(props ListProps) {
if len(props.Items) > 0 {
{{lister:=iif(props.Ordered,ol,ul) }}
@lister(){
for _, item := range props.Items {
<li>{ item } </li>
}
}
} Not much less in terms of lines of code, but could be reused elsewhere. This does rely on the Raw Go experimental functionality. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
Is it possible to render dynamic elements? Like
<svelte:element>
for exampleThere's a lot of repetition here:
Beta Was this translation helpful? Give feedback.
All reactions