In Slim, when should I use double equals sign?
For example:
== yield
== render 'partial'
== stylesheet_link_tag "application", media: "all"
title == full_title(yield(:title))
- flash.each do |key, value|
== value
or
= yield
= render 'partial'
= stylesheet_link_tag "application", media: "all"
title == full_title(yield(:title))
- flash.each do |key, value|
= value
A double equal sign means “is equal to.” Notice the line above involving the double equal sign? It is saying if the navigator application name is equal to Internet Exploder. A single equal sign means “is.”
= is used for assigning values to a variable, == is used for comparing two variables, but it ignores the datatype of variable whereas === is used for comparing two variables, but this operator also checks datatype and compares two values.
A single equals sign means assignment whereas a double equals sign means a conditional expression.
In Python and many other programming languages, a single equal mark is used to assign a value to a variable, whereas two consecutive equal marks is used to check whether 2 expressions give the same value . (x==y) is False because we assigned different values to x and y.
=
inserts HTML with escaped characters. Example:
= javascript_include_tag("1", "2")
==
inserts HTML without escaping. It is needed when you have already rendered HTML and you need to insert it to your layout directly. Example:
== render 'footer'
From the documentation:
Output =
The equal sign tells Slim it's a Ruby call that produces output to add to the buffer.
Output without HTML escaping ==
Same as the single equal sign (=), but does not go through the escape_html method.
Update regarding HTML escaping:
First of all, what "html escape" means is this:
puts html_escape('is a > 0 & a < 10?')
# => is a > 0 & a < 10?
Then, some reading about why/when you want to do it:
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