by
clemens
(02.02.2022)
Atoms are not automatically converted to strings in heex templates
tl;dr
If you’ve got a heex template where you want to insert some data attribute like true
, make sure that you convert it to a string first.
Otherwise a blank string ""
is inserted.
E.g. if you’ve got something like this:
<div class="foobar"
{ if assigns[:multi_select] != nil, do: [{"data-multi-select", Map.get(assigns, :multi_select, true)}] }>
where the assigns[:multi_select]
value is true
, you must explicitly cast the value to a string:
<div class="foobar"
{ if assigns[:multi_select] != nil, do: [{"data-multi-select", to_string(Map.get(assigns, :multi_select, true))}] }>