-
Notifications
You must be signed in to change notification settings - Fork 142
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
Add attributes to partials #440
Comments
Have you considered using a Option 1 ( fn my_fancy_btn(icon_name: &str, title: &str, some_attr: Attribute) -> Markup {
html! {
@match some_attr {
Attribute::HxGet(url) => {
button.some.button.classes title=(title) hx-get=(url) {
(icon(icon_name))
}
},
Attribute::HxDelete(url) => {
button.some.button.classes title=(title) hx-delete=(url) {
(icon(icon_name))
}
},
_ => todo!()
}
}
} Option 2 ( fn my_fancy_btn(icon_name: &str, title: &str, some_attr: Attribute) -> Markup {
match some_attr {
Attribute::HxGet(url) => html! {
button.some.button.classes title=(title) hx-get=(url) {
(icon(icon_name))
}
},
Attribute::HxDelete(url) => html !{
button.some.button.classes title=(title) hx-delete=(url) {
(icon(icon_name))
}
},
_ => todo!()
}
} Of course both possibilities are more verbose than the solution you are interested in. I just wanted to offer a workaround for your specific issue in case you were not aware how to resolve it. |
Thanks for the reply. In cases where it just one attribute I did exactly this, but with more attributes it is not rly maintainable. I also used
With a series of optionals in other cases where nested matches would have been way too much. Still think that the ability to pass attributes directly would be great and would be willing to try implementing that. |
I know there have already been some issues regarding dynamic attributes, but I want to make this one for my specific case.
I am using maud together with htmx and want to create reusable components.
Given this simple example component I want to add different hx-* attributes to the button depending on where I use it.
Possible solutions would be an
Attribute
function parameter similar to theMarkup
type (In this case a list of attributes would also need to be possible)And/Or an option to add attributes to the root element of the
Markup
type:Syntax for this one may need some tweeking
The text was updated successfully, but these errors were encountered: