Vibe.d diet templates
WebFreak001
d.forum at webfreak.org
Thu Jun 17 09:16:56 UTC 2021
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.
More information about the Digitalmars-d-learn
mailing list