Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between single and double equals in Slim (= vs ==)

Tags:

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
like image 229
Dan Avatar asked Nov 27 '14 13:11

Dan


People also ask

What is difference between single equal and double equal?

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.”

What is the difference between single equal and == double equal in Javascript?

= 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.

What is the difference between when a single equals sign is used and a double equals sign is used?

A single equals sign means assignment whereas a double equals sign means a conditional expression.

What is the difference between single equal and == double equal in Python?

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.


2 Answers

  1. = inserts HTML with escaped characters. Example:

    = javascript_include_tag("1", "2")
    
  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'
    
like image 78
Малъ Скрылевъ Avatar answered Sep 22 '22 17:09

Малъ Скрылевъ


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 &gt; 0 &amp; a &lt; 10?

Then, some reading about why/when you want to do it:

  • Do I really need to encode '&' as '&amp;'?
  • http://text-symbols.com/html/encode/
  • http://www.w3schools.com/html/html_entities.asp
like image 29
sebkkom Avatar answered Sep 23 '22 17:09

sebkkom