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

ActivePatternlab-plugin[Templating &amp; Views](/categories/templating)

evanlovely/plugin-twig-namespaces
=================================

Twig Namespaces for Pattern Lab

v1.1.1(8y ago)8415.4k↓16.7%1[3 issues](https://github.com/EvanLovely/plugin-twig-namespaces/issues)MITPHPPHP &gt;=5.4

Since Oct 11Pushed 8y agoCompare

[ Source](https://github.com/EvanLovely/plugin-twig-namespaces)[ Packagist](https://packagist.org/packages/evanlovely/plugin-twig-namespaces)[ Docs](http://patternlab.io)[ RSS](/packages/evanlovely-plugin-twig-namespaces/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

[![Packagist](https://camo.githubusercontent.com/3996d21f1d27dcac2d0d9feb9650a9e8ab4ed96f530c788df39d686c92b76359/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6576616e6c6f76656c792f706c7567696e2d747769672d6e616d657370616365732e737667)](https://packagist.org/packages/evanlovely/plugin-twig-namespaces) [![Gitter](https://camo.githubusercontent.com/1aab01ee0e000a7579622d70bc989eedef838c7d907e28309101419e0afd7b1d/68747470733a2f2f696d672e736869656c64732e696f2f6769747465722f726f6f6d2f7061747465726e2d6c61622f7068702e737667)](https://gitter.im/pattern-lab/php)

Twig Namespaces Plugin for Pattern Lab
======================================

[](#twig-namespaces-plugin-for-pattern-lab)

This adds namespaces to Twig in Pattern Lab.

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

[](#installation)

To add this plugin to your project using [Composer](https://getcomposer.org/) type:

```
composer require evanlovely/plugin-twig-namespaces

```

See Packagist for [information on the latest release](https://packagist.org/packages/evanlovely/plugin-twig-namespaces).

Usage
-----

[](#usage)

In `config.yml`, add this:

```
plugins:
  twigNamespaces:
    enabled: true
    roots:
      - ../root1
      - ../root2
    namespaces:
      foo:
        recursive: true
        paths:
          - ../bar
          - ../baz
```

Paths are relative to `composer.json` and `vendor/` in the same directory as the config directory (not config file). Assuming this folder structure

- pattern-lab/
    - config/
        - config.yml
    - composer.json
- root1/
    - 01-mountains/
        - hood.twig
    - 02-rivers
        - sandy.twig
- bar/
    - item1.twig
    - subdir/
        - subitem1.twig
- baz/
    - item2.twig

You could now use this in Twig:

```
{% include "@mountains/hood.twig" %}
{% include "@rivers/sandy.twig" %}
{@ include "@foo/item1.twig" %}
{@ include "@foo/subitem1.twig" %}
{@ include "@foo/item2.twig" %}
```

You can use either the `roots` or the `namespaces` approach without the other. The `roots` approach is how Pattern Lab registers the namespaces of all folders under `source/_patterns/` like `@atoms` and is therefore useful for including files from other Pattern Labs (watch out for namespace collisions - i.e. you can only have one `@atoms`). And the `namespaces` approach is how the Drupal [Component Libraries](https://www.drupal.org/project/components) module registers Twig namespaces, though it could also be used to register the core modules template files in Pattern Lab so you could `{% extend "@blocks/block.html.twig" %}` if you'd like. If using `namespaces` and you set `recursive: true`, then it will add all sub directories.

Also, you can set `twigNamespaces.readFromFile` to a path to a JSON or Yaml file and it will read those contents and use it in place of `twigNamespaces.namespaces`.

Disabling the Plugin
--------------------

[](#disabling-the-plugin)

To disable the plugin you can either directly edit `./config/config.yml` or use the command line option:

```
php core/console --config --set plugins.twigNamespaces.enabled=false

```

---

**Happy Pattern Labbing!**

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~131 days

Total

4

Last Release

3111d ago

Major Versions

v0.1.0 → v1.0.02016-10-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/987cdfed8075c463b2a985c2b4e05b7041b4e97f243f77cc29e4c85a8791a515?d=identicon)[EvanLovely](/maintainers/EvanLovely)

---

Top Contributors

[![EvanLovely](https://avatars.githubusercontent.com/u/569699?v=4)](https://github.com/EvanLovely "EvanLovely (6 commits)")[![alanburke](https://avatars.githubusercontent.com/u/286566?v=4)](https://github.com/alanburke "alanburke (1 commits)")

---

Tags

twigpattern lab

### Embed Badge

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

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

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

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[twig/string-extra

A Twig extension for Symfony String

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

A Twig extension to allow inlining CSS

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

Twig components for Symfony

21914.8M162](/packages/symfony-ux-twig-component)[pattern-lab/patternengine-twig

Twig-based PatternEngine for Pattern Lab.

771.3M11](/packages/pattern-lab-patternengine-twig)

PHPackages © 2026

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