1.1.7 • Published 5 years ago
otpl-js v1.1.7
OTPL
A simple template system, write once run everywhere with JavaScript (nodejs or in browser ), PHP ...
Your contributions are welcomed
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" />