PHP code example of defstudio / template-processor
1. Go to this page and download the library: Download defstudio/template-processor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
defstudio / template-processor example snippets
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)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.