Text templating

I’ve been looking for a way to shove text into javascript or a web-page, to be used _elsewhere_, in a programmatic fashion.
Nothing worked in a way that pleased me.


But then I found the below inside of dropkick.js:


// HTML template for the dropdowns
    dropdownTemplate = [
      '<div class="dk_container {{ classname }}" id="dk_container_{{ id }}" tabindex="{{ tabindex }}">',
        '<a class="dk_toggle">',
          '<span class="dk_label">{{ label }}</span>',
          '<span class="select-icon"></span>',
        '<div class="dk_options">',
          '<ul class="dk_options_inner">',



Basically, it’s each line of code (or text)

  • in an array
  • on a separate line
  • in single quotes
  • followed by a comma.
  • and joined at the end.

So you have the visual benefit of multiple lines, with the end-result of being smooshed together into one unit
You could join with a carriage-return, or <br /> if you needed to

See Also