PHPackages                             astroshippers/docx-template - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. astroshippers/docx-template

ActiveLibrary[Templating &amp; Views](/categories/templating)

astroshippers/docx-template
===========================

Make new .docx files from a Handlebars-like template (variables, conditionals, loops, table-row repetition).

v0.1.1(yesterday)01↑2900%MITPHPPHP ^8.5.0CI passing

Since Jun 8Pushed yesterdayCompare

[ Source](https://github.com/astroshippers/docx-template)[ Packagist](https://packagist.org/packages/astroshippers/docx-template)[ Fund](https://www.paypal.com/paypalme/enunomaduro)[ GitHub Sponsors](https://github.com/nunomaduro)[ RSS](/packages/astroshippers-docx-template/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (7)Versions (3)Used By (0)

DocxTemplate
============

[](#docxtemplate)

Make new `.docx` files from a Handlebars-like template.

Write a Word document with `{{placeholders}}`, `{{#if}}`, `{{#unless}}`, and `{{#each}}` blocks — then render it with a map of assigns to produce a fresh `.docx`. Word frequently splits a single placeholder across multiple `` runs (fonts, spellcheck markers, tracked changes); DocxTemplate heals those before substitution so your templates just work.

> **Requires [PHP 8.5+](https://php.net/releases/)**

Installation
------------

[](#installation)

```
composer require astroshippers/docx-template
```

Usage
-----

[](#usage)

```
use DocxTemplate\Template;

$bytes = Template::load('invoice.docx')->render([
    'customer' => 'Acme Corp',
    'items' => [
        ['name' => 'Widget', 'qty' => 3],
        ['name' => 'Gadget', 'qty' => 1],
    ],
    'paid' => true,
]);

file_put_contents('invoice-acme.docx', $bytes);
```

Template syntax inside the `.docx`:

```
Hello {{customer}}!

{{#each items}}
  - {{name}} × {{qty}}
{{/each}}

{{#if paid}}Thanks for your payment.{{/if}}
{{#unless paid}}Please remit within 30 days.{{/unless}}

```

`{{#each}}` wrapping a single `` repeats the table row.

`{{image var}}` standalone in a paragraph embeds an image. Pass it as `['bytes' => binary, 'format' => 'png', 'width_cm' => 5, 'height_cm' => 3]` in assigns.

Inspect a template's variables without rendering:

```
$vars = Template::load('invoice.docx')->variables();
// => ['customer', 'items', 'name', 'paid', 'qty']
```

Development
-----------

[](#development)

```
composer test      # Run the full test suite
composer lint      # Run Pint linter
composer refactor  # Run Rector dry-run
```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23292709?v=4)[Ostap Brehin](/maintainers/osbre)[@osbre](https://github.com/osbre)

---

Top Contributors

[![osbre](https://avatars.githubusercontent.com/u/23292709?v=4)](https://github.com/osbre "osbre (16 commits)")

---

Tags

phptemplateworddocxhandlebars

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/astroshippers-docx-template/health.svg)

```
[![Health](https://phpackages.com/badges/astroshippers-docx-template/health.svg)](https://phpackages.com/packages/astroshippers-docx-template)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
