Skip to content

llacroix/knockout-lazy-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Knockout lazy-template

It is a small binding that lets you auto download templates for knockoutjs. If your templates are located in a structured way and you can let say get them by template name. Then this plugin might be what you are looking for.

How to use:

Load the file located in the folder src after loading knockoutjs.

On any element and virtual element you can write something like this

<div data-bind="lazy-template: 'reports', data: $data"></div>

In your code you'll have to call init before applying bindings with a loader function.

The loader function takes two parameters:

  • name: name of the template
  • callback: a callback function that returns the content of the template as text

You can init the plugin like this:

ko.lazyTemplate.init({
    loader: function (name, callback){
        jQuery.get('/templates/' + name + '.html', callback);
    }
});

In this example, we get the template with jQuery and send back the result to the template. As long as the template isn't fetched, nothing will be displayed.

About

Load templates when needed automagically

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published