v0.6.15, struggling to set the "download" <a> attribute dynamically #3109
-
Hello, hope this is the right place to ask such a question. I'm creating a basic wrapper component for an anchor element that is sometimes a download link, sometimes a link to an external site.. From what I can tell, if you write an attribute like
.. but when I try to do this in a view macro (please excuse the pseduocode):
The resulting HTML is |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Unfortunately I think you might be misreading the source code: the snippet you posted sets the attribute value for a boolean attribute to Note that this is perfectly valid HTML for a Boolean attribute, for which I have no idea why they designed
Fair enough. This suggests a (hopefully easy?) solution to me, though: rather than setting If it needs to be conditional, you can use 0.7 (git main) adopts the more minimal approach for boolean attributes of simply using the attribute name, for what it's worth. |
Beta Was this translation helpful? Give feedback.
-
Setting it to an empty string is a brilliant solution, thanks a ton. The behavior of "download" is definitely a bit weird.. not anywhere near the strangest quirks of HTML, but still. Glad to hear about the 0.7 change, it does seem more sensible overall. With some luck it will not introduce new weird hyper-specific issues ! |
Beta Was this translation helpful? Give feedback.
Unfortunately I think you might be misreading the source code: the snippet you posted sets the attribute value for a boolean attribute to
if *include { attr_name }
, and later checks to see if the value is empty. So, it rendersdownload="download"
here.Note that this is perfectly valid HTML for a Boolean attribute, for which
foo
,foo=""
, andfoo="foo"
are all supposed to behave the same.I have no idea why they designed
download
to work a bit differently than that. Experimenting a little shows m…