Giter VIP home page Giter VIP logo

jquery-autobars's Introduction

jQuery Autobars

A convenient jquery plugin for loading handlebars templates declared in script tags!

Usage

jQuery-autobars's sweet spot is cases where you want to have your handlebars templates in their own file/files.

This plugin makes the distinction between partials files (which can hold multiple handlebars templates) and full templates which are one per file.

You can load a handlebar template to load into $.handlebarTemplates["compiled template"] with the script tag.

	<script src="/main.hbs" type="text/x-handlebars-template"></script>

Autobars looks at the src and downloads the code as needed, compiles it into a handlebars template and adds the method to the $.handlebarTemplates space where you can use it in your projects!!

A partials file contains several handlebar template source files and are between

	<!--#?index-->
	  handlebars code goes here
	<!--#?end-->

Handlebars helper knows its a a partials file via a script tag with type

	<script src="/helper-templates.hbs" type="text/handlebar-partials"></script>

in this case the type="text/handlebar-partials" marks the file for additional parsing.

The name after the ? in the top indicates the name the template will have in the partials namespace and can be accessed at the handlebarTemplates namespace under jquery.

	$(document).autoBars(function() {
		/* you pass a callback in to perform work on the templates
		becasuse handlebar helper is making multiple aynchrous requests
		and it makes sure to not call this callback till all the necessary files
		are loaded into the $.handlebarsTemplates namespace.
		*/
        console.log('it worked!!')
        var $html = $.handlebarTemplates.partials.index({
            message: "hello welcome to handlebar helper!!",
        });
        $('body').append($html);
      });

jquery-autobars's People

Contributors

cultofmetatron avatar

Watchers

 avatar  avatar  avatar

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.