Skip to content

jianghai/vjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mar 18, 2015
a386896 · Mar 18, 2015

History

8 Commits
Aug 1, 2014
Apr 30, 2014
Apr 30, 2014
Nov 7, 2014
Jul 4, 2014
Nov 6, 2014
Nov 6, 2014
Mar 18, 2015
Nov 7, 2014

Repository files navigation

vjs is a javascript template engine for nodejs or the browser.

In the browser

template

<script type="text" id="vjsTest">
<ul>
<% for (var i = 0; i < data.length; i++) { %>
    <li>
    <%- data[i].name %>
    <% if (data[i].age) { %>
        <br><strong class="age"><%- data[i].age %></strong>
    <% } else { %>
        <br><font color="red">Unknown</font>
    <% } %>
    </li>
<% } %>
</ul>
</script>

javascript

(function() {
    var data = [{
        name: 'jianghai',
        age: 24
    }, {
        name: 'zhouyang',
        age: 25
    }, {
        name: 'hanyu'
    }];
    var template = vjs(vjsTest.text);
    document.body.innerHTML = template(data);
})();

In the nodejs

npm install vjs
var vjs  = require('vjs');
// Same logic as browser

Document

  • vjs() Convert template string to javascript code, return a function which has a parameter data and return html string.

  • vjs.global Global object name in the template scop, default is 'data'

  • vjs.leftTag Left tag symbol in the template scop, default is '<%'

  • vjs.rightTag Right tag symbol in the template scop, default is '%>'

About

Javascript String-based templating

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published