Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
shadz3rg committed Nov 18, 2023
1 parent e8a77c6 commit ecaf43d
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
PHPStamp
=========
Your donations are always appreciated!
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=6L3DRXVG67Z2N&currency_code=EUR&amount=2&source=url)

PHPStamp is a simple PHP templating engine for XML-based Microsoft Word documents.
Library aims to provide native XML-way of templating for DOCX documents as an altenative to treating its content as a string for regex replacing, which has a lot of downsides.
PHPStamp is a simple templating engine for [XML-based Microsoft Word documents](https://learn.microsoft.com/en-us/office/open-xml/word/structure-of-a-wordprocessingml-document?tabs=cs).
Library aims to provide native XML-way of templating for DOCX documents as an alternative to treating its content as a plain text for regex replacing, which has a lot of downsides.
Instead it tries to clean messy WYSIWYG-generated code and create reusable XSL stylesheet from document.

Some additional information:
(EN) https://redd.it/30conp
(RU) http://habrahabr.ru/post/244421/
(RU) https://habr.com/ru/articles/244421/

Features
----
- Caching XSL template to filesystem for fast document render.
- Track document mode - generate and cache new template if original document was updated.
- Configurable brackets for placeholder tags.
- Basic extension system, which helps generating content blocks such as Cells or ListItems.
- Basic extension system, which helps to generate content blocks such as Cells or ListItems.

Known issues
----
Values inserted into placeholder tags may be highlighted as incorrect by spellcheck, since library removes language attribute and MS Word tries to check it with system language.

Requirements
----
Library requires PHP 5.3+ with DOM, XSL and Zip extensions.
Also depends on ```doctrine2/Lexer``` package.
Library requires PHP 7.4+ with DOM, XSL, Zip extensions.

Installation
----
Install with Composer.
Install with Composer:

`composer require shadz3rg/php-stamp`

Usage
----

##### Template.
##### Template:

![alt tag](https://habrastorage.org/files/0bf/dbf/f89/0bfdbff896ba45e1ac966c54abd050aa.png)

![alt tag](https://habrastorage.org/files/0bf/dbf/f89/0bfdbff896ba45e1ac966c54abd050aa.png)
```php
<?php
require 'vendor/autoload.php';
Expand All @@ -49,7 +47,7 @@ Usage
$cachePath = 'path/to/writable/directory/';
$templator = new Templator($cachePath);

// Enable debug mode to generate template with every render call.
// Enable debug mode to re-generate template with every render call.
// $templator->debug = true;

// Enable track mode to generate template with every original document change.
Expand All @@ -58,26 +56,26 @@ Usage
$documentPath = 'path/to/document.docx';
$document = new WordDocument($documentPath);

$values = array(
$values = [
'library' => 'PHPStamp 0.1',
'simpleValue' => 'I am simple value',
'nested' => array(
'nested' => [
'firstValue' => 'First child value',
'secondValue' => 'Second child value'
),
],
'header' => 'test of a table row',
'students' => array(
array('id' => 1, 'name' => 'Student 1', 'mark' => '10'),
array('id' => 2, 'name' => 'Student 2', 'mark' => '4'),
array('id' => 3, 'name' => 'Student 3', 'mark' => '7')
),
'students' => [
['id' => 1, 'name' => 'Student 1', 'mark' => '10'],
['id' => 2, 'name' => 'Student 2', 'mark' => '4'],
['id' => 3, 'name' => 'Student 3', 'mark' => '7']
],
'maxMark' => 10,
'todo' => array(
'todo' => [
'TODO 1',
'TODO 2',
'TODO 3'
)
);
]
];
$result = $templator->render($document, $values);

// Now you can get template result.
Expand All @@ -96,6 +94,6 @@ Usage
// echo $result->output();
```

##### Result.
##### Result:

![alt tag](https://habrastorage.org/files/290/6aa/6e6/2906aa6e6cba4fa08655b1f58463a4d8.png)

0 comments on commit ecaf43d

Please sign in to comment.