https://github.com/defstudio/template-processor
https://github.com/defstudio/template-processor
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/defstudio/template-processor
- Owner: defstudio
- Created: 2021-02-18T16:24:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T12:15:37.000Z (almost 2 years ago)
- Last Synced: 2025-11-27T09:56:04.167Z (6 months ago)
- Language: PHP
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### lowriter installation on docker
```dockerfile
ARG ENABLE_LIBREOFFICE_WRITER=0
RUN if [ ${ENABLE_LIBREOFFICE_WRITER} = 1 ] ; then \
mkdir -p /usr/share/man/man1 \
&& mkdir -p /.cache/dconf && chmod -R 777 /.cache/dconf \
&& apt-get update \
&& apt-get install -y --no-install-recommends openjdk-11-jre-headless \
&& apt-get install -y --no-install-recommends libreoffice-writer \
&& apt-get install -y --no-install-recommends libreoffice-java-common ;\
fi;
```
### Usage
```php
use DefStudio\TemplateProcessor\Elements\Image;Template::from($dock_template_path)
->compile([
// will replace all instances of ${single_key} with BAR
'single_key' => 'BAR',
// and will repeat the block enclosed by ${array_key}[...]${/array_key}
'array_key' => [
['name' => 'paul', 'age' => '36'], // with the name and age of each element of the array
['name' => 'john', 'age' => '24'],
['name' => 'ringo', 'age' => '48'],
['name' => 'george', 'age' => '22']
],
// will replace an image named ${signature} with the one passed as argument
// you can set the image name with [right click on image]→properties→options→Name
'signature' => new Image(path: '/var/www/storage/app/signature.png', keep_ratio: true))
])
// Each action can be done as a standalone call
->set('single_key', 'Bar')
->clone(block_name: 'users', variable_replacements: [
['name' => 'paul', 'age' => '36'],
['name' => 'ringo', 'age' => '48'],
['name' => 'george', 'age' => '22'],
])
->insert_image('signature', new Image(path: '/var/www/storage/app/signature.png', keep_ratio: true))
//add ->to_pdf() to convert to .pdf, otherwise an .odt file will be built
->to_pdf()
// stores the document in a file
->store($output_file)
// or returns a BinaryFileResponse
->download($dowloaded_file_name)
```
### notes
- template processor tries to cleanup its variables/block identifiers, if it is failing the detection, make sure to select and apply "cancel formatting" to them