otpl-js

1.1.7 • Public • Published

OTPL

A simple template system, write once run everywhere with JavaScript (nodejs or in browser ), PHP ...

Your contributions are welcomed

NPM

Setup with npm

$ npm install otpl-js

Run Build

$ npm run build

Run Test

$ npm run test:run

Use case

Input: your template.otpl file content

    <label for="<% $.input.id %>"><% $.label.text %></label>
    <input <% @HtmlSetAttr($.input) %> />

Usage: nodejs

 
var otpl = require('otpl-js');
var data = {
        'label' : {
            'text' : 'Your password please :',
        },
        'input' : {
            'id' : 'pass_field',
            'type' : 'password',
            'name' : 'pass'
        }
    };
//get otpl instance
var o = new otpl();
//parse your template
    o.parse('template.otpl');
//run your templated with your input data 
var output = o.runWith(data);
 
    console.log(output);

Usage: browser

 
var data = {
        'label' : {
            'text' : 'Your password please :',
        },
        'input' : {
            'id' : 'pass_field',
            'type' : 'password',
            'name' : 'pass'
        }
    };
 
//get otpl instance
var o = new OTpl();
//parse your template
    o.parse('template.otpl');
//run your templated with your input data 
var output = o.runWith(data);
 
    console.log(output);
 

Usage: php

 
    $otpl = new \OTpl\OTpl();
    $otpl->parse('template.otpl');
    $data = array(
        'label' => array(
            'text' => 'Your password please :',
        ),
        'input' => array(
            'id' => 'pass_field',
            'type' => 'password',
            'name' => 'pass'
        )
    );
 
    $otpl->runWith($data);
 

Output

    <label for="pass_field">Your password please :</label>
    <input type="password" id="pass_field" name="pass" />

Readme

Keywords

Package Sidebar

Install

npm i otpl-js

Weekly Downloads

2

Version

1.1.7

License

MIT

Unpacked Size

60.8 kB

Total Files

34

Last publish

Collaborators

  • silassare