-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support for dynamic HTML element tags inside html macro #1049
Comments
I think this would be a fun issue to take on for someone interested in how the macro works! I think we would probably need to require that the expression inside the curly braces is exactly the same for the open and close tags to have proper compile time error checks. |
@jstarry I'd like to work on it |
Alright, have fun! |
@jstarry Could you please give me start point? Should I treat computable tag name as a tag, or I should add new type Should parsing logic go here? How you debug your changes? Also, I've tried to use use cfg_if::cfg_if;
use cfg_match::cfg_match; above code don't work Thanks! |
Treat it as a tag 👍
Yes 😄
For this stuff, I try to write tests first. If you want to do debug printing, you will have to add a dependency to wasm logger on the yew-macro crate |
We can't rely on expressions resolving to the same string for start and end tags. I think we will need to special case end tags to something like |
@jstarry I was just toying around with this a bit over at siku2/yew@dynamic-tag and I noticed this exact problem:
However, my approach introduces a new syntax using the let wrapper_tag = "div";
let mut extra_iter = vec!["a", "b"].into_iter();
html! {
<@{wrapper_tag}>
<span>"Hello World"</span>
</@>
<@{extra_iter.next().unwrap()} class="extra-a"/>
<@{extra_iter.next().unwrap()} class="extra-b"/>
} The benefit of doing it this way is that it's immediately obvious that it's not a normal HTML tag and personally I think the closing tag |
@siku2 sounds reasonable to me. I'm not too worried about the syntax here since I don't expect this to be super common. Using |
Please support for dynamic changes to the HTML elements inside html macro,so that the following compiles:
The text was updated successfully, but these errors were encountered: