PHPackages                             smnandre/twigdoc - 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. smnandre/twigdoc

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

smnandre/twigdoc
================

Documentation and validation tool for Twig templates

v0.9.0(5mo ago)01MITPHPPHP &gt;=8.3CI passing

Since Dec 13Pushed 5mo agoCompare

[ Source](https://github.com/smnandre/twigdoc)[ Packagist](https://packagist.org/packages/smnandre/twigdoc)[ RSS](/packages/smnandre-twigdoc/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

TwigDoc
=======

[](#twigdoc)

> Document Twig templates, validate their inputs early, and ship confident UI changes.

 [![PHP Version](https://camo.githubusercontent.com/c556cbfdc942fb1b38ad3c01bfb2571e41449d498aa076bbe072d068cad6dbb4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332b2d6135643661373f6c6f676f436f6c6f723d364142373645266c6162656c436f6c6f723d303130)](https://camo.githubusercontent.com/c556cbfdc942fb1b38ad3c01bfb2571e41449d498aa076bbe072d068cad6dbb4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332b2d6135643661373f6c6f676f436f6c6f723d364142373645266c6162656c436f6c6f723d303130) [![CI](https://camo.githubusercontent.com/a121a9ec5fcf8f58a4b4ed7cc00db60f3f1ac701abf7147e2fa023551a0bb064/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d6e616e6472652f74776967646f632f43492e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d333838653363)](https://camo.githubusercontent.com/a121a9ec5fcf8f58a4b4ed7cc00db60f3f1ac701abf7147e2fa023551a0bb064/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d6e616e6472652f74776967646f632f43492e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d333838653363) [![Release](https://camo.githubusercontent.com/773b219222d352edab9d69ac46cad51eac372258413da53b0dc162939ada3cbe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736d6e616e6472652f74776967646f633f6c6162656c3d537461626c65266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d343361303437)](https://camo.githubusercontent.com/773b219222d352edab9d69ac46cad51eac372258413da53b0dc162939ada3cbe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736d6e616e6472652f74776967646f633f6c6162656c3d537461626c65266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d343361303437) [![GitHub Sponsors](https://camo.githubusercontent.com/4cd34878abecbe785785110fd775ebfaa34e5bb3812b45e661a42c5e632a0f0c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f736d6e616e6472653f6c6f676f3d6769746875622d73706f6e736f7273266c6f676f436f6c6f723d363662623661266c6f676f53697a653d6175746f266c6162656c3d25323053706f6e736f72266c6162656c436f6c6f723d30313026636f6c6f723d613564366137)](https://github.com/sponsors/smnandre) [![License](https://camo.githubusercontent.com/f865b36cfe186ae4853ba6de981adadaaf3501bbd927aabfc9ac172dc1feb1df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736d6e616e6472652f74776967646f633f6c6162656c3d4c6963656e7365266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d326537643332)](https://camo.githubusercontent.com/f865b36cfe186ae4853ba6de981adadaaf3501bbd927aabfc9ac172dc1feb1df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736d6e616e6472652f74776967646f633f6c6162656c3d4c6963656e7365266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30313026636f6c6f723d326537643332)

[TwigDoc](https://github.com/smnandre/twigdoc) is a zero-config companion for Twig projects. It extracts `@var`annotations, turns them into documentation, and lets you fail fast by validating template contexts during development, CI, or custom tooling.

---

Features
--------

[](#features)

*Write documentation where it matters*

: Keep `@block`, `@var`, nullable hints, and array shapes beside the Twig markup they describe.

*Generate shareable documentation*

: Build HTML or Markdown portals from annotations with `twigdoc generate`, complete with search, folder trees, and placeholder coverage tracking.

*Validate template inputs early*

: `TwigDoc::validate()` and the `twigdoc validate` command compare runtime data to the declared contract so CI or local dev trips on missing fields before reviewers do.

---

Install
-------

[](#install)

```
composer require smnandre/twigdoc
```

The CLI lives in `vendor/bin/twigdoc`; the PHP API is namespaced under `TwigDoc\`.

Usage
-----

[](#usage)

### Generate Reports: `twigdoc generate`

[](#generate-reports-twigdoc-generate)

Turn annotations into HTML or Markdown docs for your team:

```
vendor/bin/twigdoc generate templates/ --output=docs --format=html --include-empty -vv
open docs/index.html
```

#### HTML output

[](#html-output)

- `docs/index.html` – a single-page app with a folder tree, responsive layout, and Cmd/Ctrl + K search.
- `docs/twigdoc_data.js` – the structured dataset (`window.TWIGDOC_DATA`) powering the SPA.

#### Markdown output

[](#markdown-output)

- `docs/index.md` – a master index with descriptions, variable counts, and links.
- Per-template Markdown files mirroring the template tree (`docs/user/profile.md`, etc.) so you can commit documentation next to source.

### Validate Templates: `twigdoc validate`

[](#validate-templates-twigdoc-validate)

Fail fast when runtime context deviates from the documented contract:

```
use TwigDoc\TwigDoc;

TwigDoc::validate(__DIR__.'/templates/user/profile.twig', [
    'username' => 'Ada Lovelace',
    'bio' => null,
    'products' => [],
]);
```

```
vendor/bin/twigdoc validate templates/
```

### Show Template Docs: `twigdoc show`

[](#show-template-docs-twigdoc-show)

Inspect the parsed documentation for a single template during reviews or pairing:

```
vendor/bin/twigdoc show templates/user/profile.twig
```

Documentation
-------------

[](#documentation)

### Doc blocks

[](#doc-blocks)

```
{#
 # @block User profile
 # @var string $username Display name
 # @var ?string $bio Optional bio
 # @var Product[] $products Purchased products
 #}
{{ username }}
```

### Reference

[](#reference)

DirectiveExampleMeaning`@var  $name [description]``@var string $title Page title`Declares a documented variable using PHP-style types.Nullable types`@var ?string $bio`Allows `null` or omission; non-nullables must exist in runtime context.Arrays`@var Item[] $items`Expects an array where every entry matches the inner type.Scalars`string`, `int`, `float`, `bool` (aliases `integer`, `double`, `boolean`).Primitives follow PHP naming.`@block ...``@block Product detail page`Adds human-friendly copy for docs and search indices.Descriptions`@var int $age User age in years`Optional free text surfaced in HTML/Markdown outputs.Anything without annotations is ignored unless you pass `--include-empty`, which creates placeholder docs for coverage tracking.

Contributing
------------

[](#contributing)

Contributions, bug reports, and RFCs are welcome! Please open [issues](https://github.com/smnandre/twigdoc/issues)or [pull requests](https://github.com/smnandre/twigdoc/pulls).

Licence
-------

[](#licence)

[TwigDoc](https://github.com/smnandre/twigdoc) is released under the MIT Licence. See [LICENSE](./LICENSE) for details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance72

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

155d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (8 commits)")

---

Tags

annotationsdocsdocumentationdocumentorphpdocsymfonytemplatestwigtwig-templatesvar

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smnandre-twigdoc/health.svg)

```
[![Health](https://phpackages.com/badges/smnandre-twigdoc/health.svg)](https://phpackages.com/packages/smnandre-twigdoc)
```

###  Alternatives

[vincentlanglet/twig-cs-fixer

A tool to automatically fix Twig code style

3348.4M67](/packages/vincentlanglet-twig-cs-fixer)[symfony/ux-twig-component

Twig components for Symfony

21814.8M162](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1635.6M72](/packages/symfony-ux-live-component)[asm89/twig-lint

Standalone twig linter.

1186.0M2](/packages/asm89-twig-lint)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

1432.0k](/packages/symfony-ux-toolkit)

PHPackages © 2026

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