Skip to content

Instantly share code, notes, and snippets.

@ianhoffman
Created May 25, 2020 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianhoffman/e0fef9ea77c2e8e0ff71beb1bc5dc152 to your computer and use it in GitHub Desktop.
Save ianhoffman/e0fef9ea77c2e8e0ff71beb1bc5dc152 to your computer and use it in GitHub Desktop.
JS Template Example
<!DOCTYPE html>
<html>
<body>
<div><h1>Testing...</h1></div>
<div class="card-list" id="card-list"></div>
</body>
<script type="text/template" id="card-list-item">
<div class="card-list-item">
<h2 class="card-title"></h2>
<span class="card-subtitle"></span>
</div>
</script>
<script type="application/javascript">
$(document).ready(function () {
var $template = $('#card-list-item');
var $html = $template.html();
var cardData = [
{
title: 'foo',
subtitle: 'bar'
},
{
title: '1',
subtitle: '77',
}
];
for (var i = 0; i < data.length; i++) {
var $card = $($html);
$card.find('.card-title').text(cardData[i].title);
$card.find('.card-subtitle').text(cardData[i].subtitle);
$('#card-list').append($card);
}
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment