PHPackages                             phpdocumentor/plugin-twig - 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. phpdocumentor/plugin-twig

Abandoned → [phpdocumentor/phpdocumentor](/?search=phpdocumentor%2Fphpdocumentor)ArchivedPhpdocumentor-plugin[Templating &amp; Views](/categories/templating)

phpdocumentor/plugin-twig
=========================

Plugin for phpDocumentor2 that adds support for creating templates using Twig as templating engine

1.0.0(13y ago)65.3kMITPHPPHP &gt;=5.3.3

Since Jul 8Pushed 13y ago3 watchersCompare

[ Source](https://github.com/phpDocumentor/plugin-twig)[ Packagist](https://packagist.org/packages/phpdocumentor/plugin-twig)[ Docs](http://www.phpdoc.org)[ RSS](/packages/phpdocumentor-plugin-twig/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

phpDocumentor Twig Plugin
=========================

[](#phpdocumentor-twig-plugin)

Important

This plugin is deprecated and will be removed once phpDocumentor 2.0 goes stable. Twig functionality will be included in the core of phpDocumentor 2.0 using an Object model instead of XML/XPath interaction.

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

[](#installation)

This plugin is installed by default with phpDocumentor.

Features
--------

[](#features)

This plugin features the following:

- A writer to generate output using Twig
- A basic extension with the most common functions and tasks related to phpDocumentor.
- An interface for Twig extensions for third-party developers to base their Twig extensions on.

Generating output using Twig
----------------------------

[](#generating-output-using-twig)

The Twig writer can be used in any transformation in a template (see phpDocumentor's main documentation on *Creating templates*).

The following line can be added as child to the transformations element:

```

```

This tells phpDocumentor to use the Twig writer to use the `index.twig`template in the `/data/templates/my_twig_template` folder to generate the `index.html` file in your destination folder.

Full basic example template:

```

  Mike van Riel
  mike.vanriel@naenius.com
  1.0.0
  Mike van Riel 2012

```

### Looping through a resultset

[](#looping-through-a-resultset)

Using transformation it is possible to loop through a set of elements and apply a template on all of them.

Easiest is to demonstrate this using an example:

*Suppose that you would want to generate a detailed view of a class using the same template file*

You do not know up front which classes there will be so you would need a dynamic transformation. This is possible by adding the 'query' attribute to your transformation and specifying a xpath lookup.

Example transformation for each class entry:

```

```

Important

Never use a `//` in your search query; this is impossibly slow and is to be avoided in all circumstances.

The above example would loop through all `class` elements of the project and pass that to your twig template as root element instead of `project`.

**There is a big problem with the transformation above:** the destination file `class.html` would be overwritten with each subsequent class found and you end up with one file with the last class found.

To fix this you can use an xpath query in your artifact attribute as well to create a dynamic destination filename.

Example transformation for each class entry with a dynamic file name:

```

```

In the above example you can see that a xpath query is provided in braces. This query is executed with the node that was found using the *query* attribute. Thus in this example the `full_name` property was taken from the class that is currently being processed.

Writing your own templates
--------------------------

[](#writing-your-own-templates)

Note

To be expanded upon

Every template receives a global Twig variable called `ast_node`. This global Twig variable represents the either the document-root of the Abstract Syntax Tree (which is project) or a childnode if a Query has been used.

Hint

if you were to do a query on `/project/file/class` then `ast_node` would be a single instance of /project/file/class.

Since the Abstract Syntax Tree (and its nodes) are presented as SimpleXMLElement objects you can query them as normal objects from Twig.

Extensions
----------

[](#extensions)

### Using third-party extensions

[](#using-third-party-extensions)

phpDocumentor allows you to add your own extensions so that they can be used.

Every extension needs to be available for autoloading (so it is common to create a Plugin in this case and include them using the Composer 'require' section).

Once available you can define a parameter 'twig-extension' in your template header of with each individual transformation.

Note

Extensions defined with a transformation override the ones defined in your template.

Example globally defined extension:

```

            \phpDocumentor\Plugin\MyPlugin\Twig\Extension

```

Example extension defined with an individual transformation:

```

                    \phpDocumentor\Plugin\MyPlugin\Twig\Extension

```

### Writing your own extensions

[](#writing-your-own-extensions)

Note

To be written

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

5060d ago

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/1323714f58f9144af310e5e4217e61b96ad7c42bc5c93a1f2d97deca95f6f4f8?d=identicon)[ashnazg](/maintainers/ashnazg)

![](https://www.gravatar.com/avatar/471baf346b526fa9e1259ee3d577b1dd72fbb45337b495d5475f87ba063490cb?d=identicon)[jaapio](/maintainers/jaapio)

---

Top Contributors

[![mvriel](https://avatars.githubusercontent.com/u/193704?v=4)](https://github.com/mvriel "mvriel (6 commits)")

---

Tags

pluginphpdoctwigdocumentationphpDocumentor

### Embed Badge

![Health badge](/badges/phpdocumentor-plugin-twig/health.svg)

```
[![Health](https://phpackages.com/badges/phpdocumentor-plugin-twig/health.svg)](https://phpackages.com/packages/phpdocumentor-plugin-twig)
```

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

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

PHPackages © 2026

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