Knockstrap provides implementation of Knockout-compatible stringTemplateEngine, which can use strings as html templates.

For developers, constructor of engine available via ko.stringTemplateEngine. Also it contains instance property, so it isn't necessary to create your own. It can be used everywhere, where Knockout's nativeTemplateEngine is acceptable.

Template engine contains storage of templates, which is shared between all instances.

API

stringTemplateEngine contains:

addTemplate(name, template)
Adds new template with given name to engine storage
removeTemplate(name)
Removes template with given name from engine storage
getTemplate(name)
Returns template with given name from engine storage or returns undefined, if there is no template
isTemplateExist(name)
Return true, if template with given name was saved in engine storage. Otherwise - false.
instance
Instance of stringTemplateEngine.

Examples

String template engine:

Native template engine:

Html markup

<p>String template engine:</p>
<p data-bind="template: { name: 'demo', templateEngine: ko.stringTemplateEngine.instance }"></p>
<p>Native template engine:</p>
<p data-bind="template: { name: 'demo' }"></p>
            
<script id="demo" type="text/html">
    <span>It's a <strong>native template engine</strong>!</span>
</script>

View model

var ste = ko.stringTemplateEngine.instance;

ste.addTemplate('demo', '<span>It\'s a <strong>string template engine</strong>!</span>');