struct components #945
Replies: 4 comments 3 replies
-
|
What you've done is very similar to what @joerdav did here (excepting the constructor methods, which I also prefer): So I'd say you're on to something decent. I use very similar patterns myself. |
Beta Was this translation helpful? Give feedback.
-
|
Yes, this is totally legit. 😀 |
Beta Was this translation helpful? Give feedback.
-
|
@smithamax yes, we are using - https://github.com/hanariu/hanariu |
Beta Was this translation helpful? Give feedback.
-
|
I'm not sure if this is just me or not, but using the mechanism you specified above: @field{Label: "Username", Name: "username", Required: true}Makes it slightly difficult to use children, as it gives an error when compiling the templ code to Go: @field{Label: "Username", Name: "username", Required: true} {
<span>Hello World!</span>
}I did manage to get around the issue by rewriting the code to look like this: @(field{Label: "Username", Name: "username", Required: true}) {
<span>Hello World!</span>
}Which, whilst it works, looks all kinds of weird to me. Can anyone else verify the error I see when the code looks like the below? @field{Label: "Username", Name: "username", Required: true} {
<span>Hello World!</span>
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've playing with using struct literals as components, and wondered if anyone is doing the same. Also is there any reason not to use this as a pattern
Example
Then
templ loginForm { <form action="/login" method="post"> @field{Label: "Username", Name: "username", Required: true} @field{Label: "Password", Name: "password", Type: "password", Required: true} <button type="submit">Provision Reader</button> </form> }One downside is that it seems to break syntax highlighting in vscode 😆

Beta Was this translation helpful? Give feedback.
All reactions