Code Monkey home page Code Monkey logo

lite-te's Introduction

Lite-TE is a simple light weight template engine.

Usage

  1. install lite-te using npm npm install lite-te --save
  2. import lite-te as var liteTE = require('lite-te');
  3. pass your html to compile function of liteTE as var template = liteTE.compile(your-html-string);
  4. the template variable now consists of bindContext function which binds your javascript object to the html. var html = template.bindContext(your-object);

Example

For node environment

var liteTE = require('lite-te');
var tempalte = liteTE.compile('<p>{{ this.profile.name }}</p><p>{{ this.profile.age }}</p>');
var html = template.bindContext({ 
    profile: {
        name: 'Hello World',
        age: '100 years'
    }
});
document.querySelector('body').innerHTML = html;

For plain javascript

  1. download the index.js file from https://github.com/KiranMantha/lite-te to the local source code folder.
  2. refer the downloaded file in the html page.
  3. access the liteTE object from window object as window.liteTE.

Example

var template = liteTE.compile('<p>{{ this.profile.name }}</p><p>{{ this.profile.age }}</p>');
var html = template.bindContext({ 
    profile: {
        name: 'Hello World',
        age: '100 years'
    }
});
document.querySelector('body').innerHTML = html;

Complex Example

in HTML

<script id="sampleTpl" type="text/lite-te">
    <div>
        <p>{{ this.name }}</p>
        <p>{{ this.age }}</p>
        <ul>
            for(var i=0; i < this.skills.length; i++) {
                <li>{{ this.skills[i] }}</li>
            }
        </ul>
    </div>
</script>

in JS

var tpl = document.getElementById('sampleTpl').innerHTML;
var template = liteTE.compile(tpl);
var html = template.bindContext({ 
    name: 'Hello World!!',
    age: 25,
    skills: ['html', 'css', 'javascript']
});
document.querySelector('div').innerHTML = html;

Note: In the above example we're not using require as we're not using node environment.

lite-te's People

Contributors

kiranmantha avatar

Watchers

James Cloos avatar Muralikrishna T 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.