Boolean attributes compile to strings #138
-
Thanks for the awesome library, it feels so natural to write compared to eex. I was excited to see LiveView support. I am having a little difficulty with boolean attributes. In eex something like works as expected. My naive temple equivalent is always disabled though because boolean is compiled to a string.
Is there are workaround for boolean attributes? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
To answer myself, while it might be possible to handle this at compile time for a static attribute as in the example, it would not work with assigns as temple is compiled away and eex doesn't handle it either. Options seem to be use |
Beta Was this translation helpful? Give feedback.
-
This is a convenience I'd like to support. Currently in my app I have a very hacky function to help with this. fieldset merge_if([], [disabled: true], not is_nil(@foo.finished_at)) do
# ...
end
def merge_if(keyword_1, keyword_2, condition) do
if condition do
Keyword.merge(keyword_1, keyword_2)
else
keyword_1
end
end |
Beta Was this translation helpful? Give feedback.
-
I've opened a PR to address this #139 |
Beta Was this translation helpful? Give feedback.
-
I've just released v0.7.0 that includes this functionality. |
Beta Was this translation helpful? Give feedback.
To answer myself, while it might be possible to handle this at compile time for a static attribute as in the example, it would not work with assigns as temple is compiled away and eex doesn't handle it either. Options seem to be use
content_tag
or disabled the button client side (with hooks in a LiveView if needed).