Using variables without interpolation
Writing out the full interpolation syntax when you don't need to actually put a variable inside of a body of text (and have all of the text for that attribute or tag directly in the variable) can be a bit annoying. So naturally, Jade gives us a shorter way. Take the following code, for example:
Jade |
HTML |
---|---|
- i = {"type": "text", "name": "Bob"} input(type="#{i.type}", value="#{i.name}") | <input type="text" value="Bob"> |
This can be rewritten as follows:
Jade |
HTML |
---|---|
- i = {"type": "text", "name": "Bob"} input(type=i.type, value=i.name) | <input type="text" value="Bob"> |
Or, consider the following example:
Jade |
HTML |
---|---|
- content = "Richardson leggings Cosby sweater, pariatur locavore Pinterest Schlitz" p #{content} | <p>Richardson leggings Cosby sweater, pariatur locavore Pinterest Schlitz</p> |
This can be rewritten as follows:
Jade |
HTML |
---|---|
- content = "Richardson leggings Cosby sweater, pariatur locavore Pinterest Schlitz" p= content | <p>Richardson... |