dev-master
9999999-devTemplate generator
MIT
The Requires
- php >=5.3.2
- cebe/markdown ~1.0.1
The Development Requires
by Bezirovoviku
template document docx
Template generator
This is simple template system for document files. It uses text replacement, allows cyclical replacements and basic filters., (*1)
You can install this library using composer, (*2)
composer require bezirovoviku/temgen
LibreOffice (2+) - only for OPDF converter, (*3)
PhantomJS - only for PPDF converter, (*4)
First you will need to include the generator class, (*5)
use Temgen\Generator;
then use generator class as follows, (*6)
//Creates generator $generator = new Generator(); //Adds basic filters $generator->addFilters(); //Sets temporary folder used to store documents $generator->setTmp('/tmp'); //Sets path to template file $generator->setTemplate(new Document('template.html')); //Generates zip archive from specified data $generator->generateArchive(json_decode($this->data, true), 'archive.zip');
To create custom filter, you will need to implement \Temgen\Generator\Filter interace, (*7)
class MyFilter implements \Temgen\Generator\Filter { /** * Returns tag used to identify filter * * @return string tag identifing filter */ public function getTag() { return 'myfilter'; } /** * Filter given arguments and return result * * @param \Temgen\Generator $generator generator calling this filter * @param array $context replacing context * @param array $arguments arguments passed to filter * @param string|null $input pipe input (if present) * @return string result */ public function filter($generator, $context, $arguments, $input) { return strtoupper($input); } }
then you will need to add instance of this filter to generator instance, like so:, (*8)
$generator = new Generator(); $generator->addFilter(new MyFilter());
now, in this generator instance, filter MyFilter will be accessible by {myfilter} syntax, (*9)
This requires libreoffice installed, (*10)
//Creates docx generator $generator = new Generator\Docx(); //PDF converter $converter = new Converter\OPDF(); //Adds basic filters $generator->addFilters(); //Sets temporary folder used to store documents $generator->setTmp('/tmp'); //Sets path to template file $generator->setTemplate(new Document\Docx('template.docx')); //Generates zip archive from specified data, converts using converter $generator->generateArchive(json_decode($this->data, true), 'archive.zip', $converter);
Template generator
MIT
template document docx