nowo-tech / word-template-bundle
Symfony bundle: fill .docx Word templates (PHPWord TemplateProcessor) from a context array — scalars, rich HTML, table rows, images.
Package info
github.com/nowo-tech/WordTemplateBundle
Type:symfony-bundle
pkg:composer/nowo-tech/word-template-bundle
Requires
- php: >=8.2 <8.6
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-zip: *
- phpoffice/phpword: ^1.3
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0
- rector/rector: ^2.0
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/yaml: ^6.4 || ^7.0 || ^8.0
Suggests
- nowo-tech/html-to-word-bundle: Optional: build .docx from full HTML when you do not use a Word template (WYSIWYG → DOCX pipeline).
This package is auto-updated.
Last update: 2026-05-08 13:10:20 UTC
README
Found this useful? Install from Packagist (
composer require nowo-tech/word-template-bundle) and consider starring WordTemplateBundle on GitHub.
Symfony bundle that fills Microsoft Word .docx templates (PHPWord TemplateProcessor) using a PHP context array:
- Scalars (strings, numbers, booleans, null) →
setValueon placeholders such as${client_name}or${client.city}when you nest arrays (flattened to dot keys). TableRows→cloneRow+ per-cell#1,#2, … replacements for repeating table lines.HtmlContent→ rich fragments (paragraphs, bold/italic, tables inside HTML, etc.) via PHPWordHtml::addHtmlembedded as a complex block (lists<ul>/<ol>may require extra numbering setup in PHPWord; prefer plain paragraphs or combine with HtmlToWordBundle for full HTML pipelines).ImageSource→setImageValuewith optional width/height.
This bundle does not execute Word VBA macros; “macros” here means template placeholders in the .docx compatible with PHPWord.
Documentation
Additional documentation
- FrankenPHP / Docker demos —
demo/symfony7anddemo/symfony8(seedemo/README.md)
Requirements
- PHP 8.2+
- Symfony 6.4 / 7.x / 8.x (as in
composer.json) - Extensions:
dom,json,libxml,zip
Quick start
composer require nowo-tech/word-template-bundle
Register Nowo\WordTemplateBundle\WordTemplateBundle if needed, then wire your templates and inject WordTemplateProcessorInterface:
use Nowo\WordTemplateBundle\Processor\WordTemplateProcessorInterface; $doc = $this->wordTemplateProcessor->process( '/path/to/template.docx', [ 'title' => 'Contract #42', 'client' => ['name' => 'ACME', 'city' => 'Madrid'], ], ); $bytes = $doc->readContents(); $doc->dispose(); // if the processor used a temp file
Tests and coverage
| Scope | Detail |
|---|---|
| PHPUnit | composer test — unit + integration (minimal kernel in tests/Fixtures/AppKernel.php). |
| Lines | composer coverage-check enforces ≥ 93% (PCOV). Última medición global: ~94%. |
Development
make up make qa make release-check
Demos (FrankenPHP)
From the repository root:
cd demo/symfony7 && cp .env.example .env && make up # Symfony 7, port 8020 cd demo/symfony8 && cp .env.example .env && make up # Symfony 8, port 8021
Or from demo/: make up / make up8 (see demo/README.md).