Skip to content
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 adding attributes through iterators #386

Open
jquesada2016 opened this issue Jul 27, 2023 · 1 comment
Open

Support adding attributes through iterators #386

jquesada2016 opened this issue Jul 27, 2023 · 1 comment

Comments

@jquesada2016
Copy link

Please foregive me if this is already possible, as I did not find it in the book. But I am trying to componentize some markup, and need to support adding arbitrary attributes. So for example, let's take an <input>

struct Input {
  attrs: Vec<(String, String)>
}

impl Render for Input {
  fn render(&self) -> Markup {
    html! {
      input type="text" ...self.attrs;
    }
  }
}

Is something like this currently possible? I understand the security implications, but this is intended to be done at compile time, by adding attributes in different parts of the app, not dynamically.

@jquesada2016
Copy link
Author

If not currently possible, perhaps iterators and a spread operator might be good additions to the syntax?

Attribute spreading needs to implement Iterator<Item = (impl Display, impl Display)> and could use the rust spread operator ..while classes can be spread via. ..or something similar? Would only need to implementIterator<Item = impl Display>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant