exhtml
7/12/2017 - 3:39 PM

more advanced system (without plugins) https://stackoverflow.com/questions/17884300/how-can-i-use-templates-with-jquery-without-additional-p


String.prototype.fillTemplate = function() {
  var args = arguments;
  return this.replace(/{(\d+)}/g, function(match, number) { 
    return typeof args[number] != 'undefined'
      ? args[number]
      : match
    ;
  });
};

var cardTemplate = $("#cardTemplate").html();

var template = cardTemplate.fillTemplate("http://example.com", "Link Title");
$("#container").append(template);

<!-- template -->
<script type="text/template" id="cardTemplate">
    <span><a href="{0}">{1}</a></span>
</script>

<!-- output -->
<div id="container"></div>