![pugjs es literals pugjs es literals](https://blog.logrocket.com/wp-content/uploads/2021/01/reactdaypicker.png)
Note that this can also be simplified somewhat by using ES6 arrow notation: However, template literals begin to come into their own when combined with functions which produce the same output. You can create a complex template literal that can reduce the amount of time embedded such content into a string. “The sequence \t puts a tab into a template literal.”Īt this stage, template literals are beginning to look interesting. String.raw`The sequence \t puts a tab into a template literal` If your string contains a number of escaped characters (such as the newline or tab character) and you don’t want to get caught up in counting slashes, you can also use the String.raw` literal form. The difference between a regular string and a template string is that in the former you need to escape every line, while in the latter you need only escape the overly long strings. Note as well that the terminating backspace character is still recognized within templates, which can be very useful when you have text that runs longer than your available screen-width.
Pugjs es literals code#
This not only handles the pain of dealing with apostrophes in conversational text (as demonstrated above), but it also makes the corresponding code considerably easier to read. The effect is instantaneous here – in effect, the backtick (or more accurately, the template literal operator) performs a conversion of carriage returns, tabs and quotes into their respective normal string representations. will give you the slash followed by the letter 'n'.”
![pugjs es literals pugjs es literals](https://pughtml.com/assets/logo.png)
\n will still get interpreted as a hard carriage return, but “You do have to double escape your escape characters, however.
![pugjs es literals pugjs es literals](https://i0.wp.com/css-tricks.com/wp-content/uploads/2017/05/basic-nunjucks.png)
With a magic quote, though, they just go away!” “Consider this – if I have to write a quote in code normally, say something like ‘This is a weird quote.’ then I have to spend a lot of time using escape characters like \" and \', and they can make for real legibility problems. “This isn’t just another quote,” Ada said. will give you the slash followed by the letter 'n'." "You do have to double escape your escape characters, however. With a magic quote, though, they just go away!" Then I have to spend a lot of time using escape characters like \\" and \\', and they can make for real \ "Consider this - if I have to write a quote in code normally, say something like 'This is a weird quote.' \ "It's a magical quote." Ĭlive settled onto the couch, one foot over the armchair rest, eyeing her dubiously. `"This isn't just another quote," Ada said. At its simplest, this solves two issues with one throw – the aforementioned one of letting you have one string with embedded carriage returns, and the not to be sneezed at ability to incorporate both single and double quotes in a string without having to escape them.Ĭonsider this code and observe what it generates below: They are also awkward, error prone, and ugly.ĮS6 introduces another way to extend strings across a single line, using the back-tick character ( `).
Pugjs es literals how to#
How to put those multiple lines in HTML? It is possible to use the + operator to join strings across multiples lines (provided you enclose them in quotes) or even just append the line with the backslash character ( "\").
![pugjs es literals pugjs es literals](https://drek4537l1klr.cloudfront.net/cantelon2/Figures/01fig01_alt.jpg)
You’ve no doubt run into this situation: you have a line of text, maybe HTML, that extends over several lines.