Best practice to render empty alt attribute of img tags on sightly

369 Views Asked by At

Writing img tags with alt attributes is expected for good code practices, but sightly automatically skips empty attributes. How to render empty alt attributes in sightly?

Having this case, where image.alt is empty

Actual result:

Expected result:

1

There are 1 best solutions below

2
Vlad On

As described in the specification, an array with just one empty string element will cause the attribute to render as empty string: https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#2231-detailed-examples:

<img src="..." alt="${myAlt || ['']}"

will render an empty alt even if myAlt is empty/falsy/null.