Compile perroquet template files into pure PHP files
npm install perroquet
`` | | | |/ _ \ __|
____ _
| _ \ ___ _ __ _ __ ___ __ _ _ _ ___| |_
| |_) / _ \ '__| '__/ _ \ / _
| __/ __/ | | | | (_) | (_| | |_| | __/ |_
|_| \___|_| |_| \___/ \__, |\__,_|\___|\__|
|_|
``
Perroquet is a small template engine that compiles into PHP. It's compiled into raw PHP files that you can run in your PHP server.
js
var php_code = perroquet('Hi my name is {{$name}}');
// php code = 'Hi my name is '
`List of template codes
| Template code | Generated php code |
|---|---|
|
{{$variable}}||
|{{$object.attribute}}|attribute; ?>|
|{{$array[key]}}||
|{{$variable = 'value'}}||
|{{$array as $value}}||| $value) {|
|{{function() as $value}}||
|{{=date(..)}}||
|{{#variable}}||
|{{url $img}}||
|{{>path}}||
|{{?variable}}||
|{{!variable}}||
|{{?variable1 && !variable2}}||
|{{if condition}}||
|{{elseif condition}}||
|{{else}}||
|{{for $i = 0; $i < 9; $i++}}||
|{{while condition}}||
|{{/}}||
|{{switch condition}}||
|{{case 'awesome'}}||
|{{bcase 'awesome'}}||
|{{default}}||
|{{break}}||
|{{pr $variable}}||
|{{js $variable}}||
|{{esc}} my escaped {{$code}} {{/esc}}| my escaped {{$code}} |Custom functions
You can add custom functions to the compiler:
`js
var php_code = perroquet('Today is the {{date Y-m-d}}', {
date: function (format) {
// format = 'Y-m-d'
return '';
}
});
`Custom delimiters
You can change the default {{..}} delimiters with the third parameter of perroquet(code, custom_functions, custom_regex). For example:
`js
var php_code = perroquet('Hi my name is --#name--', null, /--(.*?)--/g);
`` To suggest a feature, report a bug, or general discussion:
http://github.com/blunt1337/perroquet/issues/