Coder Social home page Coder Social logo

tuncatakan / load-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miketimmerman/load-template

0.0 0.0 0.0 216 KB

With this piece of javascript code you can organise your Handlebars templates in separate files and retrieve them via a simple API.

JavaScript 100.00%

load-template's Introduction

Load template

With this piece of javascript code you can organise your Handlebars templates in separate files and retrieve them via a simple API.

Currently it only works in browsers that support XMLHttpRequest.

How to use it?

The first step is to load the Handlebars library and this script in the HTML file.

<script src="assets/js/handlebars.js"></script>
<script src="assets/js/loadTemplate.js"></script>

Then you have Initiate a new template. The first parameter can be a string of the ID or a reference of the element itself. The second parameter is the filename of the template. And the last parameter (not required) is an object that you want to send to the template.

var tpl = new LoadTemplate('id', 'titles-overview', {'data':'data1'});

It will search for your template in the folder assets/template/. This can easilly be changed to an other directory, by changing the following line.

this.folderPath = 'assets/templates/';

Now you can call the create method. You can provide a callback, this will be executed after the template is loaded and placed in the parent element.

tpl.create(function(){ ... });

..Or you can use the createAndWait method. This method is simular to the one above, but the template and element will be send back to the callback so you can determine when the template is placed on the page. This method can be usefull when you want to retrieve some data from an API and use this in the template.

tpl.createAndWait(function(template, element){ ... });

load-template's People

Contributors

miketimmerman 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.