vibe.d diet - is there a way to use a D variable inside the "parameters" of a tag

Steven Schveighoffer schveiguy at gmail.com
Thu Dec 31 18:58:49 UTC 2020


On 12/29/20 3:22 PM, Chris Bare wrote:
> On Tuesday, 29 December 2020 at 20:16:40 UTC, Chris Bare wrote:
>> I'm trying to generate a list of buttons and insert the value 
>> programmatically.
>> Here's what I've tried:
>>         - foreach (i; ["Prev", "Replay", "Next"])
>>             input(type="button",value=#{i})
>> that does not compile.
>> if instead I use:
>>             input(#{i})
>> It compiles, but generates: <input #{i}>
>>
>> Is there a way to double escape the variable, or is substitution just 
>> not supported there?
> 
> One minute after I sent this I tried:
> input(type="button",value=i)
> 
> and that works.

Yes. Just one thing to be aware of, if i is a boolean, then the behavior 
is to include "value" or not include "value" in the element.

In other words:

sometag(foo=true) => <sometag foo="foo"> (or something like that)
sometag(foo=false) => <sometag >

The only other annoying thing is that you can't use interpolations for 
classes directly using pug syntax, you have to use class attributes 
inside the parentheses.

-Steve


More information about the Digitalmars-d mailing list