digitalmars.D.learn - vibe.d selectively include attribute into tag using diet template
- JG (18/18) Feb 27 2021 Hi,
- Steven Schveighoffer (11/32) Feb 27 2021 Yes, if you assign a boolean value to it directly, then if true, the
- JG (5/12) Feb 27 2021 Thank you very much for this.
- Steven Schveighoffer (9/16) Feb 28 2021 So if you have an expression as the right side of an attribute
- JG (3/20) Mar 01 2021 Thanks
Hi, I know that one can do the following: But, is there a way to deal with attributes that don't get assigned values. That is, is there a way to produce <tag> or <tag attribute> depending on a boolean variable? Of course one can do: - if (booleanVariable) tag(attribute) include ... - if (!booleanVariable) tag include ... But this seems rather messy.
Feb 27 2021
On 2/27/21 12:48 PM, JG wrote:Hi, I know that one can do the following: But, is there a way to deal with attributes that don't get assigned values. That is, is there a way to produce <tag> or <tag attribute> depending on a boolean variable? Of course one can do: - if (booleanVariable) tag(attribute) include ... - if (!booleanVariable) tag include ... But this seems rather messy.Yes, if you assign a boolean value to it directly, then if true, the attribute is included, if not, it's not. e.g.: tag(attribute=booleanVariable) Note the lack of quotes. If you us an expression without quotes in diet, it becomes an interpolation. In the special case that it's a boolean, it becomes a switch to tell whether to include the attribute or not. If it's a complex expression you might need parentheses: tag(attribute=(booleanVariable ? true : false)) -Steve
Feb 27 2021
On Saturday, 27 February 2021 at 19:12:55 UTC, Steven Schveighoffer wrote:Yes, if you assign a boolean value to it directly, then if true, the attribute is included, if not, it's not. e.g.: tag(attribute=booleanVariable) Note the lack of quotes.Thank you very much for this.If you use an expression without quotes in diet, it becomes an interpolation.Would you mind explaining in more detail what this means? How could one use this, other than with booleans?
Feb 27 2021
On 2/28/21 12:29 AM, JG wrote:On Saturday, 27 February 2021 at 19:12:55 UTC, Steven Schveighoffer wrote:So if you have an expression as the right side of an attribute assignment, it is treated as a D expression, which is then evaluated and turned into string form. So e.g. your original example: can be written as: tag(attribute=dexpression) -SteveIf you use an expression without quotes in diet, it becomes an interpolation.Would you mind explaining in more detail what this means? How could one use this, other than with booleans?
Feb 28 2021
On Sunday, 28 February 2021 at 18:10:26 UTC, Steven Schveighoffer wrote:On 2/28/21 12:29 AM, JG wrote:ThanksOn Saturday, 27 February 2021 at 19:12:55 UTC, Steven Schveighoffer wrote:So if you have an expression as the right side of an attribute assignment, it is treated as a D expression, which is then evaluated and turned into string form. So e.g. your original example: can be written as: tag(attribute=dexpression) -SteveIf you use an expression without quotes in diet, it becomes an interpolation.Would you mind explaining in more detail what this means? How could one use this, other than with booleans?
Mar 01 2021