PHPackages                             drupal-pattern-lab/attach-library-twig-extension - 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. drupal-pattern-lab/attach-library-twig-extension

ActiveLibrary

drupal-pattern-lab/attach-library-twig-extension
================================================

Twig function that lets Pattern Lab use a simple version of Drupal's attach\_library function to add javascript files per component.

v1.1.0(7y ago)4331.2k↑10.7%6[2 issues](https://github.com/drupal-pattern-lab/attach-library-twig-extension/issues)[4 PRs](https://github.com/drupal-pattern-lab/attach-library-twig-extension/pulls)1MITPHP

Since Aug 13Pushed 7y ago2 watchersCompare

[ Source](https://github.com/drupal-pattern-lab/attach-library-twig-extension)[ Packagist](https://packagist.org/packages/drupal-pattern-lab/attach-library-twig-extension)[ RSS](/packages/drupal-pattern-lab-attach-library-twig-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (1)

attach-library-twig-extension
=============================

[](#attach-library-twig-extension)

Twig function that lets Pattern Lab use a simple version of Drupal's [attach\_library](https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module#twig) function to add javascript files per component.

Requirements
------------

[](#requirements)

To use in Pattern Lab, simply place in the `_twig-components/functions` directory. Since this function is specifically for Pattern Lab (Drupal has its own), it is namespaced with `pl_` so if you're using the [Unified Twig Extensions](https://github.com/drupal-pattern-lab/unified-twig-extensions/) module, it will ignore it when syncing functions between Drupal and Pattern Lab.

Usage
-----

[](#usage)

Simply add `{{ attach_library(MODULE/FILENAME) }}` to any component Twig file using the same syntax as Drupal. Pattern Lab will then locate the theme's `*.libraries.yml` file and load the JavaScript file from the path in that library whenever that component is loaded. Since this function uses the same syntax as Drupal, nothing else needs to be done when loading the component in Drupal. It will work as it always did!

Current Limitations
-------------------

[](#current-limitations)

This function is limited to loading the js file referenced in the library. It will not load other assets and will not load any dependencies either. If you need to load a dependency or other file in Pattern Lab, it can be done as usual in `/meta/foot.twig`. See the commented out parts in [Emulsify's file](https://github.com/fourkitchens/emulsify/blob/develop/components/_meta/_01-foot.twig) for examples of how to do this.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~113 days

Total

2

Last Release

2722d ago

### Community

Maintainers

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

---

Top Contributors

[![philwolstenholme](https://avatars.githubusercontent.com/u/6339853?v=4)](https://github.com/philwolstenholme "philwolstenholme (5 commits)")

### Embed Badge

![Health badge](/badges/drupal-pattern-lab-attach-library-twig-extension/health.svg)

```
[![Health](https://phpackages.com/badges/drupal-pattern-lab-attach-library-twig-extension/health.svg)](https://phpackages.com/packages/drupal-pattern-lab-attach-library-twig-extension)
```

PHPackages © 2026

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