javascript multiline strings in the code  [ 705 views ]

Goal: use multiline strings in the code

I have a simple string template. I want to store it in a variable but I want to forget the concatenation.
We can use the following trick.


  var itemTemplate = `<li>
      <div class="direction-r">
        <div class="flag-wrapper">
          <span class ="flag">${0}</span>
          <span class ="time-wrapper">${1}</span>
        </div>
        <div class ="desc">${2}</div>
      </div>
    </li>`;

  console.log(itemTemplate);

the trick is the GRAVE ACCENT character -> `

see also: GRAVE ACCENT

#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }