On Thursday, 17 June 2021 at 09:16:56 UTC, WebFreak001 wrote:
On Thursday, 17 June 2021 at 08:23:54 UTC, JG wrote:
Suppose I have an array of attributes and values v is there
any way to apply these attributes to a tag?
So that something like
tag(#{v[0]0]}=#{v[0][1]},...})
becomes
<tag attribute0=value0 ....>
where v[0][0]="attribute0" and v[0][1]="value0"?
I think there is nothing for this built-in in diet, so you have
to manually emit raw HTML:
```diet
- import std.xml : encode;
- auto start = appender!string;
- start ~= "<tag";
- foreach (pair; v)
- start ~= " ";
- start ~= pair[0].encode;
- start ~= "=\"";
- start ~= pair[1].encode;
- start ~= '"';
- start ~= ">";
|!= start
// content here
|!= "</tag>"
```
Maybe some attribute splat operator would be nice for this.
Thanks, this works. I would have thought this would be a common
enough use case to have support in diet. Anyone else wanted this?