Skip to content

Latest commit

 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WordTemplateBundle

CI Packagist Version Packagist Downloads License PHP Symfony GitHub stars Coverage

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) → setValue on placeholders such as ${client_name} or ${client.city} when you nest arrays (flattened to dot keys).
  • ConditionalBlock${#if block}${#endif block} regions (several sibling and nested blocks supported); show or remove from PHP. Markers split across Word runs are healed before apply.
  • TableRowscloneRow + per-cell #1, #2, … replacements for repeating table lines (several independent tables in one .docx via distinct anchors; one TableRows per table row).
  • HtmlContent → rich fragments (paragraphs, bold/italic, tables inside HTML, etc.) via PHPWord Html::addHtml embedded 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).
  • ImageSourcesetImageValue with optional width/height.
  • listVariables() → unique paint placeholder names (includes fields inside conditionals; omits #if / #endif markers).
  • listConditionalBlocks() → unique conditional block names (e.g. annex from ${#if annex}). This bundle does not execute Word VBA macros; “macros” here means template placeholders in the .docx compatible with PHPWord. Under FrankenPHP (especially worker mode), process() is bounded by a configurable timeout (default 180s, cooperative deadline + set_time_limit) so a long merge cannot pin a worker forever. See docs/CONFIGURATION.md and docs/DEMO-FRANKENPHP.md (REQ-RUNTIME-001).

FrankenPHP Friendly Worker Mode

This bundle is FrankenPHP worker mode friendly.

Versioning

Semantic Versioning.

Quick start

composer require nowo-tech/word-template-bundle:^1.3

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

Requirements

  • PHP 8.2+
  • Symfony 7.x / 8.x (as in composer.json)
  • Extensions: dom, json, libxml, zip

Development

make up
make qa
make release-check

Demos (FrankenPHP)

Demos run with FrankenPHP (Caddy + PHP in Docker). docker-compose defaults to APP_ENV=dev, so the entrypoint uses Caddyfile.dev (no PHP worker), and Twig/PHP changes are visible on refresh. Worker mode applies to a production-style setup — see docs/DEMO-FRANKENPHP.md.

From the repository root:

cd demo/symfony8 && cp .env.example .env && make up   # Symfony 8, port 8021

Or from demo/: make up (see demo/README.md).

Documentation

Additional documentation

Tests and coverage

Scope Detail
PHPUnit composer test — unit + integration (minimal kernel in tests/Fixtures/AppKernel.php).
Lines composer coverage-check enforces ≥ 99% (PCOV). Latest global measurement: ~100%.

License

MIT License.

About

Symfony bundle that fills Microsoft Word .docx templates using PHPWord TemplateProcessor and a PHP context array.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages