Skip to content

Commit 7da2169

Browse files
committed
update ReadMe
1 parent 026fbe6 commit 7da2169

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,67 @@ Installation
66
Install with Composer.
77

88
`composer require totalcrm/docx-templator`
9+
10+
11+
##### Template.
12+
![alt tag](https://habrastorage.org/files/0bf/dbf/f89/0bfdbff896ba45e1ac966c54abd050aa.png)
13+
14+
```php
15+
<?php
16+
require 'vendor/autoload.php';
17+
18+
use TotalCRM\DocxTemplator\Templator;
19+
use TotalCRM\DocxTemplator\Document\WordDocument;
20+
21+
$cachePath = 'path/to/writable/directory/';
22+
$templator = new Templator($cachePath);
23+
24+
// Enable debug mode to generate template with every render call.
25+
// $templator->debug = true;
26+
27+
// Enable track mode to generate template with every original document change.
28+
// $templator->trackDocument = true;
29+
30+
$documentPath = 'path/to/document.docx';
31+
$document = new WordDocument($documentPath);
32+
33+
$values = array(
34+
'library' => 'Templator 0.1',
35+
'simpleValue' => 'I am simple value',
36+
'nested' => array(
37+
'firstValue' => 'First child value',
38+
'secondValue' => 'Second child value'
39+
),
40+
'header' => 'test of a table row',
41+
'students' => array(
42+
array('id' => 1, 'name' => 'Student 1', 'mark' => '10'),
43+
array('id' => 2, 'name' => 'Student 2', 'mark' => '4'),
44+
array('id' => 3, 'name' => 'Student 3', 'mark' => '7')
45+
),
46+
'maxMark' => 10,
47+
'todo' => array(
48+
'TODO 1',
49+
'TODO 2',
50+
'TODO 3'
51+
)
52+
);
53+
$result = $templator->render($document, $values);
54+
55+
// Now you can get template result.
56+
// 1. HTTP Download
57+
$result->download();
58+
59+
// Or
60+
// 2. Save to file
61+
$saved = $result->save(__DIR__ . '/static', 'result.docx');
62+
if ($saved === true) {
63+
echo 'Saved!';
64+
}
65+
66+
// Or
67+
// 3. Buffer output
68+
echo $result->output();
69+
```
70+
71+
##### Result.
72+
![alt tag](https://habrastorage.org/files/290/6aa/6e6/2906aa6e6cba4fa08655b1f58463a4d8.png)

0 commit comments

Comments
 (0)