I'm trying to get Slim to generate the following HTML if a CONDITION is true:
<div id="start_button" hidden="hidden">
I have tried various methods, like the obvious:
#start_button #{('hidden="hidden"' if CONDITION?)}
= link_to 'Get Started', ...etc...
but that generates:
<div id="start_button">hidden="hidden"
= link_to 'Get Started',..etc...
I know how to do it when setting an attribute like class etc. to something, but because it has got to be all or nothing with "hidden", it's causing me issues.
I've been down quite a few rabbit holes this evening, so any help appreciated!
This is stated in the docs:
Ruby attributes
Write the ruby code directly after the =. If the code contains spaces you have to wrap the code into parentheses (...). You can also directly write hashes {...} and arrays [...].
So, anything that's inside ()
is evaluated as Ruby code, if the statement is evaluated to false, it's somehow "skipped", otherwise it does what's stated in the true branch.
#start_button hidden=('hidden' if true)
<div hidden="hidden" id="start_button"></div>
#start_button hidden=('hidden' if false)
<div id="start_button"></div>