Skip to content

Instantly share code, notes, and snippets.

@andersdn
Last active January 29, 2017 06:48
Show Gist options
  • Save andersdn/4b03c7253fdfc19827d7 to your computer and use it in GitHub Desktop.
Save andersdn/4b03c7253fdfc19827d7 to your computer and use it in GitHub Desktop.

Revisions

  1. andersdn revised this gist Nov 30, 2015. No changes.
  2. andersdn revised this gist Nov 30, 2015. No changes.
  3. andersdn revised this gist Nov 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ function _tpl(templateName,callback) {
    $(document).ready(function(){

    var template_data = {
    'foor':'bar'
    'foo':'bar',
    'baz':['apple','bananna','custard']
    };
    _tpl('dashboard',function(template){
  4. andersdn revised this gist Nov 30, 2015. 2 changed files with 1 addition and 1 deletion.
    File renamed without changes.
    2 changes: 1 addition & 1 deletion main.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // underscore template loader
    function _tpl(templateName,callback) {
    var tmpl_url = templateName + '.html';
    var tmpl_url = '_tlp-' + templateName + '.html';
    $.ajax({
    url: tmpl_url,
    method: 'GET',
  5. andersdn revised this gist Nov 30, 2015. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -14,13 +14,13 @@ function _tpl(templateName,callback) {

    $(document).ready(function(){

    var template_data = {
    'foor':'bar'
    'baz':['apple','bananna','custard']
    };
    _tpl('dashboard',function(template){
    var tpl = _.template(template);
    $("#container").html(tpl(template_data));
    })
    var template_data = {
    'foor':'bar'
    'baz':['apple','bananna','custard']
    };
    _tpl('dashboard',function(template){
    var tpl = _.template(template);
    $("#container").html(tpl(template_data));
    })

    })
  6. andersdn revised this gist Nov 30, 2015. 2 changed files with 1 addition and 1 deletion.
    File renamed without changes.
    2 changes: 1 addition & 1 deletion main.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // underscore template loader
    function _tpl(templateName,callback) {
    var tmpl_url = templateName + '.tpl';
    var tmpl_url = templateName + '.html';
    $.ajax({
    url: tmpl_url,
    method: 'GET',
  7. andersdn created this gist Nov 30, 2015.
    9 changes: 9 additions & 0 deletions dashboard.tpl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <html>
    <body>
    <h1>Foo is <%= foo %></h1>
    <% _.each(baz,function(value,index){ %>
    <h2>Baz <%= index %> is <%= value %>
    <h2>
    <% }) %>
    </body>
    </html>
    10 changes: 10 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <html>
    <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="main.js"></script>
    </head>
    <body>
    <div id="container"></div>
    </body>
    </html>
    26 changes: 26 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    // underscore template loader
    function _tpl(templateName,callback) {
    var tmpl_url = templateName + '.tpl';
    $.ajax({
    url: tmpl_url,
    method: 'GET',
    async: false,
    contentType: 'text',
    success: function (data) {
    callback(data);
    }
    });
    }

    $(document).ready(function(){

    var template_data = {
    'foor':'bar'
    'baz':['apple','bananna','custard']
    };
    _tpl('dashboard',function(template){
    var tpl = _.template(template);
    $("#container").html(tpl(template_data));
    })

    })