Just to help other developers, because there is no similar question on SO.
div class=(is_active? ? 'active' : 'inactive') div class=('active' if is_active?)
Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.
Definition of slim file : a file very narrow in proportion to its length.
HTML comment /!Use the forward slash immediately followed by an exclamation mark for html comments ( <! -- ... --> ).
Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner. Slim also adds if-else statements, loops, includes, and more.
See the examples below:
div class=(is_active? ? 'active' : 'inactive') div class=('active' if is_active?)
The same approach can be used to assign dynamic values to other attributes.
I use array of classes and nil element if there is no need to include class in list, then compact array to remove nil elements and finally join all together.
div class=(["cday", "col-md-1", day.day == 1 ? "col-md-offset-#{day.cwday-1}" : nil].compact.join(' '))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With