Advertisement
khangnguyen

js-template

Sep 8th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Original HTML generator
  2. var HTMLCode = '<h1>' + pageTitle + '</h1><div id="content"><p>' + pageContent + '</p><div id="author_bio"><p>' + authorBio +'</p></div></div><div id="footer"><p>' + footerContent + '</p></div>';
  3.  
  4. # Better improvement with line breaks and format
  5. var HTMLCode =  '\n' +
  6.                 '<h1>' + pageTitle + '</h1>\n'
  7.                 '<div id="content">\n' +
  8.                   '<p>' + pageContent + '</p>\n' +
  9.                   '<div id="author_bio">\n' +
  10.                     '<p>' + authorBio + '</p>\n' +
  11.                   '</div>\n'                '</div>\n' +
  12.                 '<div id="footer">' +
  13.                   '<p>' + footerContent + '</p>\n' +
  14.                 '</div>\n';
  15.  
  16. # JS HTML Template
  17. <script type="text/plain" id="entry-template">
  18.   <h1><%- pageTitle %></h1>
  19.   <div id="content">
  20.      ...
  21.   </div>
  22. </script>
  23. var EntriesView = Backbone.View.extend({
  24.     template: _.template($("#entry-template").html()),
  25.     render: function() {
  26.         return self.template(data);
  27.     });
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement