The Velocity template engine is available in JavaScript and PHP. See velocity.apache.org for the official Java version of Apache.

Quick to use

Template rendering

The Render method combines a VM template string and a data object into a string, for example:

var tmpl = 'My name is ${name}. I\ 'm a #if($gender == "male")boy#{else}girl#end.';
var data = {
    name: 'June',
    gender: 'female'
};
window.velocity.render(tmpl, data); // "My name is June. I'm a girl."Copy the code

PHP version

After the velvelocity. PHP file is introduced, the Main class of the namespace PhpVelocity sets the compilation path and the vm file update check switch through the constructor. The RENDER method synthesizes a string of vm files and data in the specified path, and can be set to clear past data. Such as:


       
include './velocity.php';
use PhpVelocity\Main as Velocity;

$compile_dir = 'path/to/compiles';

$ve = new Velocity($compile_dir.true); //Set the compile path and check the VM template file for updates before each render (no updates are checked by default) and recompile if there are any

$data = array("name" = > "June"."gender" = > "female");
echo $ve->render('path/to/template1.vm'.$data); //Render templates and data
echo $ve->render('path/to/template2.vm'); //Apply colours to a drawing template
$data = array("name" = > "Apple"."price" = > 10000);
echo $ve->render('path/to/template3.vm'.$data.true); //Render templates and data, clear past dataCopy the code

The project structure

The path meaning
/src/antlr Antlr Paradigm development for Velocity.
/src/debug Web programs for development and debugging.
/src/* Implementation source code for Each language version of Velocity, including all dependencies.
/build/*/velocity.* Each language version of the Velocity executable should be provided bysrcPackaging.
/test/cases Test cases, each containing one of the same name.vmFiles and a.jsonFile.
/test/diff The result comparator compares the output of each language version of TestRunner, and is generated in this directoryresult.htmlReport file.
/test/*/src TestRunner source code for each language version; The TestRunner runtime does not require input parameters and simply reads case files and prints them to their respective filesoutputDirectory.
/test/*/run.sh Test run scripts for each language version.
/test/*/output/*.html Output of TestRunner for each language version, one case for each output file.

License

MIT

Copyright (c) 2017-present, shenfe