https://github.com/silassare/otpl-js
A simple & lightweight template system: write once compile everywhere with JavaScript, PHP ...
https://github.com/silassare/otpl-js
javascript nodejs otpl template template-engine
Last synced: 3 months ago
JSON representation
A simple & lightweight template system: write once compile everywhere with JavaScript, PHP ...
- Host: GitHub
- URL: https://github.com/silassare/otpl-js
- Owner: silassare
- License: mit
- Created: 2016-10-27T18:03:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-04-02T16:32:46.000Z (about 3 years ago)
- Last Synced: 2025-02-13T21:05:09.899Z (4 months ago)
- Topics: javascript, nodejs, otpl, template, template-engine
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# OTPL
A simple template system, write once run everywhere with JavaScript (nodejs or in browser ), PHP ...
## Your contributions are welcomed
- [JS Project](https://github.com/silassare/otpl-js/)
- [PHP Project](https://github.com/silassare/otpl-php/)[](https://www.npmjs.com/package/otpl-js)
## Setup with npm
```sh
$ npm install otpl-js
```## Run Build
```sh
$ npm run build
```## Run Test
```sh
$ npm run test:run
```## Use case
### Input: your template.otpl file content
```html
<% $.label.text %>
/>
```### Usage: nodejs
```javascript
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
```javascript
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
```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
```html
Your password please :
```