PHPackages                             nystudio107/twig-bundle-installer - 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. nystudio107/twig-bundle-installer

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

nystudio107/twig-bundle-installer
=================================

Install, update, and manage Twig template bundles via Composer

1.1.2(1y ago)361.1k21MITPHPPHP &gt;=5.4

Since Feb 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nystudio107/twig-bundle-installer)[ Packagist](https://packagist.org/packages/nystudio107/twig-bundle-installer)[ Docs](https://nystudio107.com)[ GitHub Sponsors](https://github.com/khalwat)[ RSS](/packages/nystudio107-twig-bundle-installer/feed)WikiDiscussions develop-v1 Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (1)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/970f7fcda77280878d54646c6b1374173b33c59145fe8b054caf0c40c86bd041/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f747769672d62756e646c652d696e7374616c6c65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nystudio107/twig-bundle-installer/?branch=master) [![Build Status](https://camo.githubusercontent.com/8fa9924215e930f53de9fb4d845fd3eb72723ebace0750457fe275fd6f411205/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f747769672d62756e646c652d696e7374616c6c65722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nystudio107/twig-bundle-installer/build-status/master) [![Code Intelligence Status](https://camo.githubusercontent.com/d0bf0638a6e06898fd087db42f6b08b0a8e50ace46e32fb480d457d9a67cfdc3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f747769672d62756e646c652d696e7374616c6c65722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

Twig Bundle Installer plugin for Composer
=========================================

[](#twig-bundle-installer-plugin-for-composer)

A Composer plugin that installs &amp; manages Twig Bundles in your `templates/vendor/` directory

[![Screenshot](./resources/twig-bundle.png)](./resources/twig-bundle.png)

Overview
--------

[](#overview)

Twig Bundle Installer is a Composer installer that installs and manages Twig Bundles in your `templates/` directory. It introduces the concept of Twig *bundles* and installs them in `templates/vendor/`, similarly to how you’d normally install PHP packages in `vendor/`. (And it doesn’t change anything about that; your PHP bundles will still live in `vendor`.)

It implements a new Composer package type named `twig-bundle`, which should be used when publishing Twig Bundles. Composer manages it all, and Twig Bundle Installer is not tied to any particular CMS or system. Anything that uses Twig might find it useful.

This allows you to install and update Twig templates across multiple projects in a managed way.

Why Though?
-----------

[](#why-though)

- Stop copying useful bits of Twig between projects; include them easily and keep them *all* up to date.
- Share useful Twig components with other developers and teams in whatever projects you want.
- Reuse these same bits anywhere you use Twig; Craft CMS, Drupal, Grav, Symfony... even Laravel, Statamic, and beyond.
- Improve your documentation once your base components all live together in one place.
- Distribute your Craft plugin’s sample templates in a more convenient, flexible, and versionable way.
- Utilize *template* dependencies as easily as PHP packages.

Why Twig Bundle Installer?
--------------------------

[](#why-twig-bundle-installer)

I'd originally thought of the idea implemented in Twig Bundle Installer when working on re-usable Twig components.

Later the idea came up again when I worked on a base Twig templating layer as discussed in the [An Effective Base Twig Templating Setup](https://nystudio107.com/blog/an-effective-twig-base-templating-setup) article.

Then it idea came up *again* when discussing with a colleague how they managed multiple brand properties in a large [Craft CMS](https://craftcms.com) install via separate plugins. Each brand site had its own custom plugin which was mostly a wrapper for the templates needed for said site.

So if something comes up 3x or more, I think it's probably worth trying out…

Using Twig Bundle Installer
---------------------------

[](#using-twig-bundle-installer)

### Consuming Twig Bundles

[](#consuming-twig-bundles)

#### Adding Twig Bundles to your Project

[](#adding-twig-bundles-to-your-project)

To use Twig Bundles in your own project, first you need to add Twig Bundle Installer to your project's `composer.json`:

```
{
  "require": {
    "nystudio107/twig-bundle-installer": "^1.0.0"
  }
}
```

Because Twig Bundle Installer is a Composer plugin, you will also need to tell Composer that's it okay to use this plugin via [`config:allow-plugins`](https://getcomposer.org/doc/06-config.md#allow-plugins) in your `composer.json` file:

```
{
  "config": {
    "allow-plugins": {
      "nystudio107/twig-bundle-installer": true
    }
  }
}
```

Then you can add in the vendor/package name of the Twig Bundle you want to use just like you would any Composer package:

```
{
  "require": {
    "nystudio107/twig-bundle-installer": "^1.0.0",
    "nystudio107/test-twig-bundle": "^1.0.0"
  }
}
```

Then just do a:

```
composer install

```

What Twig Bundle Installer does is for Composer packages that are of the type `twig-bundle` instead of putting them in the `vendor/` directory, it will put them in the `templates/vendor/` directory.

In the above example, you'll end up with something like this:

```
❯ tree -L 4 templates/vendor
templates/vendor
└── nystudio107
    └── test-twig-bundle
        ├── CHANGELOG.md
        ├── composer.json
        ├── LICENSE.md
        ├── README.md
        └── templates
            ├── fizz-buzz.twig
            ├── elementary-my-dear-watson.twig
            └── five-minute-read.twig

3 directories, 8 files

```

This means that you can install &amp; update these Twig Bundles across multiple projects. They can be Twig Bundles you've created, or Twig Bundles others have created.

It works just like any Composer package does, because Twig Bundle Installer is just a layer on top of Composer that routes packages of the type `twig-bundle` to a different directory.

Commands you're used to such as `composer require`, `composer update`, etc. all work as you'd expect.

Example including a template from a Twig Bundle:

```
{% include 'vendor/nystudio107/test-twig-bundle/templates/fizz-buzz.twig' %}
```

#### Twig Bundle Considerations

[](#twig-bundle-considerations)

Since Twig Bundle Installer is looking for a directory in your project root named `templates/` that points to your Twig templates directory:

- You should treat the `templates/vendor/` directory as **read only** just like you do the `vendor/` directory
- If you store your templates somewhere else, you can create a symlink or alias from `templates/` to where you store your templates, or you can set the `TEMPLATES_VENDOR_DIR` environment variable (either in the environment itself, or in your `.env` file in your project root if you're using [Dotenv](https://github.com/vlucas/phpdotenv))
- If you exclude your `vendor/` directory from your Git repo, you probably would want to add `templates/vendor/` to your `.gitignore` as well. Twig Bundle Installer will automatically put `.gitignore` file in the `templates/vendor/` directory for you

Example `.gitignore` file:

```
/vendor
/templates/vendor

```

#### Local Repositories

[](#local-repositories)

If you want to use local Twig Bundles while you work on them, you can do that via the [Composer Repositories](https://getcomposer.org/doc/05-repositories.md) setting:

```
{
  "require": {
    "nystudio107/bundle-twig-installer": "^1.0.0",
    "nystudio107/twig-test-bundle": "^1.0.0"
  },
  "repositories": [
    {
      "type": "path",
      "url": "../../twig/*",
      "options": {
        "symlink": true
      }
    }
  ]
}
```

Where the `url` setting is a path to where your source Twig Bundles live.

### Creating Twig Bundles

[](#creating-twig-bundles)

To create a Twig Bundle, create a directory with a `Composer.json` file in it that looks like this:

```
{
  "name": "nystudio107/test-twig-bundle",
  "description": "Test bundle of Twig templates for Bundle Installer",
  "version": "1.0.0",
  "keywords": [
    "twig",
    "twig-bundle",
    "composer",
    "installer",
    "bundle"
  ],
  "type": "twig-bundle",
  "license": "MIT",
  "minimum-stability": "stable"
}
```

...but obviously change the `name` to your `vendor/bundle` name, and fill in your own description, etc. The key is that you must have the `type` set to `twig-bundle`:

```
  "type": "twig-bundle",

```

You'll then want to publish this to a [GitHub](https://github.com/) or other Git repo, publish it on [Packagist.org](https://packagist.org/) so others can install it via Composer

If you've never published a package on Packagist before, just follow the instructions on [Packagist.org](https://packagist.org/) or read the [Packagist and the PHP ecosystem](https://www.bugsnag.com/blog/packagist-and-the-php-ecosystem) article.

You can use the [Test Twig Bundle](https://github.com/nystudio107/test-twig-bundle) as an example to follow.

Twig Bundle Installer Roadmap
-----------------------------

[](#twig-bundle-installer-roadmap)

This project is usable as-is, but it's also very much in the germination phase. I'm curious to see what uses people find for it, or potentially none at all.

Some ideas:

- Bundles could include CSS and JavaScript that the installer builds a `manifest.json` for something else to consume
- Framework specific tools could compliment Twig Bundle Installer by automatically publishing bundles on the frontend
- Technically, the technique described here would work fine for [Antlers](https://docs.statamic.com/antlers) or [Blade](https://laravel.com/docs/5.8/blade) and other templating systems as well.

Brought to you by [nystudio107](https://nystudio107.com/)

###  Health Score

36

—

LowBetter than 81% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.3% 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 ~417 days

Total

5

Last Release

608d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7570798?v=4)[Andrew Welch](/maintainers/khalwat)[@khalwat](https://github.com/khalwat)

---

Top Contributors

[![khalwat](https://avatars.githubusercontent.com/u/7570798?v=4)](https://github.com/khalwat "khalwat (36 commits)")[![mattstein](https://avatars.githubusercontent.com/u/2488775?v=4)](https://github.com/mattstein "mattstein (1 commits)")

---

Tags

composerbundletwigdrupalinstallercraftcmssymphony

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nystudio107-twig-bundle-installer/health.svg)

```
[![Health](https://phpackages.com/badges/nystudio107-twig-bundle-installer/health.svg)](https://phpackages.com/packages/nystudio107-twig-bundle-installer)
```

###  Alternatives

[yellowskies/qr-code-bundle

Symfony Barcode &amp; QR Code Generator Bundle with Twig extension

36682.9k](/packages/yellowskies-qr-code-bundle)[nystudio107/craft-autocomplete

Provides Twig template IDE autocomplete of Craft CMS &amp; plugin variables

44204.4k13](/packages/nystudio107-craft-autocomplete)[pattern-lab/drupal-twig-components

A collection of Twig components to be used with Drupal- and Twig-related StarterKits.

17849.9k2](/packages/pattern-lab-drupal-twig-components)[jalendport/craft-preparse

A fieldtype that parses Twig when an element is saved and saves the result as plain text.

1086.4k](/packages/jalendport-craft-preparse)

PHPackages © 2026

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