index.html 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!-- This is a first example of using a template -->
  2. <head>
  3. <!-- include our libraries and css files -->
  4. <script src="js/jquery-2.1.4.min.js"></script>
  5. <script src="js/handlebars-v3.0.3.js"></script>
  6. <script src="js/bootstrap.min.js"></script>
  7. <link href="css/bootstrap.css" rel="stylesheet">
  8. <link href="css/gallery.css" rel="stylesheet">
  9. </head>
  10. <body>
  11. <!-- the content of the web page starts off empty
  12. because we will fill it later from the template -->
  13. <div id="content">
  14. </div>
  15. <!-- this is our template
  16. it displays an image with a title and author headings
  17. the bits in curly brackets {{}} are template expressions -->
  18. <script id="image-template" type="text/x-handlebars-template">
  19. <div class="title">
  20. <h1>{{title}}</h1>
  21. <h3 class="author">
  22. {{author}}
  23. </h3>
  24. <img style="height:600" src="{{src}}" />
  25. </div>
  26. </script>
  27. <!-- javascript code to fill the template -->
  28. <script type="text/javascript">
  29. // grab our template code from the DOM
  30. var source = $("#image-template").html();
  31. // compile the template so we can use it
  32. var template = Handlebars.compile(source);
  33. // create some data
  34. var data = {
  35. src: "images/The_Earth_seen_from_Apollo_17.jpg",
  36. title: "The Earth seen from Apollo 17",
  37. author: "Ed g2s"
  38. };
  39. // generate HTML from the data
  40. var html = template(data);
  41. // add the HTML to the content div
  42. $('#content').html(html);
  43. </script>
  44. </body>