GithubHelp home page GithubHelp logo

hbs-tiny-loader's Introduction

.hbs tiny loader

.hbs tiny loader

Here is a little work around to load your handelbars template files (.hbs).

Handelbars is great javascript template engine to work with. But to keep things organized I like to put my templates in separate files. So you need to gather them with a little AJAX call. There is where .hbs tiny loader will make your life easier.

.hbs tiny loader comes in two flavors, asynchronous and synchronous. You can pick one by choosing the right branch of this repo.

Requirements

  • handelbars
  • jQuery
  • .hbs tiny loader

So you need to include those scripts at the end of your HTML body tag.

  [...]
  <script type="text/javascript" charset="utf-8" src="js/jquery.3.2.1.js"></script>
  <script type="text/javascript" charset="utf-8" src="js/handlebars.4.0.11.js"></script>
  <script type="text/javascript" charset="utf-8" src="js/jquery.handlebars.hbs-tiny-loader.min.js"></script>
  <script type="text/javascript" charset="utf-8" src="js/script.js"></script>
</body>

Exemples

Considering this file structure:

root/
├── js/
│   ├── handlebars.4.0.11.js
│   ├── jquery.3.2.1.js
│   ├── jquery.handlebars.hbs-tiny-loader.min.js
│   └── script.js
├── templates/
│   └── template.hbs
└── index.html

Asynchronous example

var path = 'templates/template.hbs';

var data     = {
  message: 'Hello hbs file!'
};

var deferred = $.getHbs(path);

deferred.then(function(template){
  var html = template(data);
  $('body').prepend(html);
});

Synchronous example

var path = 'templates/template.hbs';

var template = $.getHbs(path);

var data     = {
  message: 'Hello hbs file!'
};
var html     = template(data);
$('body').prepend(html);

Have fun with handlebars and keep things organized. 😉

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.