Setting valueless boolean attributes with the tag function When using the tag function, how does one handle valueless attributes which could also be null?
For example, it's great we can do…
{% set idVar   = 'idstring' %}
{% set nameVar = 'namestring' %}
{% set typeVar = 'typestring' %}

{{ tag('input', {
    id: idVar,
    name: nameVar,
    type: typeVar
}) }}

…to generate:
&lt;input id=&quot;idstring&quot; name=&quot;namestring&quot; type=&quot;typestring&quot;&gt;

But what about if the required attribute is also a variable? We can’t do:
{% set reqVar  = '' %}

{% if field is required %}
    {% set reqVar = 'required' %}
{% endif %}

{{ tag('input', {
    id: idVar,
    name: nameVar,
    required: reqVar
}) }}

…because if reqVar is empty, one would want the required attribute to not be written at all. To generate:
&lt;input id=&quot;idstring&quot; name=&quot;namestring&quot; type=&quot;typestring&quot;&gt;

…and not:
&lt;input id=&quot;idstring&quot; name=&quot;namestring&quot; type=&quot;typestring&quot; required&gt;

The same thing applies to other boolean attributes like hidden.
Is there a way to do this with this function? What am I missing or not getting?
If an attribute is set to true, it will get added without a value.
{{ tag('input', {
    id: idVar,
    name: nameVar,
    required: true
}) }}

Also, if it is set to null or false, it will be omitted, as if it was never listed in the first place.