PHPackages                             pixo/labcoat - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pixo/labcoat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pixo/labcoat
============

Pattern Lab utilities

v1.0.2(10y ago)71.3k3[1 issues](https://github.com/pixotech/labcoat/issues)NCSAPHP

Since Nov 24Pushed 9y ago9 watchersCompare

[ Source](https://github.com/pixotech/labcoat)[ Packagist](https://packagist.org/packages/pixo/labcoat)[ Docs](http://pixotech.com/)[ RSS](/packages/pixo-labcoat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (12)Used By (0)

Labcoat: Pattern Lab for Production
===================================

[](#labcoat-pattern-lab-for-production)

Labcoat is a library for using Pattern Lab content in live site environments. It provides the ability to:

- [Render pattern templates](#rendering-pattern-templates)
- [Generate style guides using the Pattern Lab UI](#generating-style-guides)
- [Validate template content](#validating-template-content)

Labcoat places the following restrictions on Pattern Lab installations:

- Twig is the only supported templating language
- Patterns can only be referenced by partial and path syntax
- Layouts, macros, and other advanced Twig features are not supported

Labcoat was created by [Pixo](http://pixotech.com/), and released under the [NCSA license](https://opensource.org/licenses/NCSA).

Pattern Lab was created by [Brad Frost](http://bradfrostweb.com) and [Dave Olsen](http://dmolsen.com), and released under the [MIT license](https://opensource.org/licenses/MIT).

Basic usage
-----------

[](#basic-usage)

Include the Labcoat library using [Composer](https://getcomposer.org/):

```
{
  "require": {
    "pixo/labcoat": "^1.0.0"
  }
}
```

The PatternLab class represents a Pattern Lab installation. For [Standard Edition installations](https://github.com/pattern-lab/edition-php-twig-standard), Labcoat needs the path to the installation root (containing `config` and `source` directories):

```
$labcoat = Labcoat\PatternLab::loadStandardEdition('/path/to/patternlab');
```

For an installation that uses Labcoat's default structure:

```
$labcoat = Labcoat\PatternLab::load('/path/to/patternlab');
```

For custom configurations, create a new Configuration object and use it as a constructor argument:

```
$config = new Labcoat\Configuration\Configuration();
$config->setPatternsPath('/path/to/pattern/templates');
$labcoat = new Labcoat\PatternLab($config);
```

- [More about Labcoat configuration](src/Configuration)

Rendering pattern templates
---------------------------

[](#rendering-pattern-templates)

Labcoat contains a [Twig loader](http://twig.sensiolabs.org/doc/api.html#loaders) class for using pattern templates in other applications.

```
$loader = new Labcoat\Twig\Loader($labcoat);
$twig = new Twig_Environment($loader, ['cache' => '/path/to/twig/cache']);
```

The loader supports two methods of [including patterns](http://patternlab.io/docs/pattern-including.html):

- **Partial syntax**, i.e. `type-name`. Fuzzy matching is *not* supported.
- **Path**, relative to the patterns directory. The file extension and any [ordering digits](http://patternlab.io/docs/pattern-reorganizing.html) are ignored.

```
# These will all render the template "00-atoms/01-icons/email.twig"
print $twig->render('atoms-email');
print $twig->render('atoms/icons/email');
print $twig->render('00-atoms/01-icons/email');
print $twig->render('00-atoms/01-icons/email.twig');
print $twig->render('123-atoms/456-icons/email.twig');

# Fuzzy matching isn't supported, so this won't work
print $twig->render('atoms-em');
```

### Caching the loader

[](#caching-the-loader)

Once created, the loader class can be stored in a cache to save time during the next request. If Memcache is available:

```
$makeLoaderIfNotInCache = function ($cache, $key, &$loader) {
  $labcoat = Labcoat\PatternLab::load('/path/to/patternlab');
  $loader = new Labcoat\Twig\Loader($labcoat);
};
$loader = $memcache->get('labcoat_loader', $makeLoaderIfNotInCache);
$twig = new Twig_Environment($loader);
```

If [Stash](http://www.stashphp.com/) is being used:

```
$item = $stash->getItem('labcoat/loader');
$loader = $item->get();
if ($item->isMiss()) {
  $item->lock();
  $labcoat = Labcoat\PatternLab::load('/path/to/patternlab');
  $loader = new Labcoat\Twig\Loader($labcoat);
  $item->set($loader);
}
$twig = new Twig_Environment($loader);
```

### Combining with other loaders

[](#combining-with-other-loaders)

The Labcoat loader can be chained with other loaders:

```
$loader = new Twig_Loader_Chain([
  new Labcoat\Twig\Loader($labcoat),
  new Twig_Loader_Filesystem('/path/to/more/templates'),
]);
$twig = new Twig_Environment($loader);
```

### Creating HTML documents

[](#creating-html-documents)

The Document class makes full HTML pages from patterns:

```
$doc = new Labcoat\Html\Document($twig->render('pages-about'));
$doc->setTitle('About Us');
$doc->includeStylesheet('/css/styles.min.css');
$doc->includeScript('/js/script.min.js');
print $doc;
```

Generating style guides
-----------------------

[](#generating-style-guides)

Labcoat can generate style guides that use the [Pattern Lab interface](https://github.com/pattern-lab/styleguidekit-assets-default)

```
$labcoat = new Labcoat\PatternLab('/path/to/patternlab');
$styleguide = new Labcoat\Styleguide\Styleguide($labcoat);
$styleguide->generate('/path/to/styleguide');
```

Use PHP's [built-in webserver](http://us1.php.net/manual/en/features.commandline.webserver.php) to browse the style guide locally (at , in this example):

```
php -S 0.0.0.0:8080 -t /path/to/styleguide
```

### Reporting

[](#reporting)

The `generate()` method returns a report object, which can be printed to obtain a summary of the generation process:

```
print $styleguide->generate('/path/to/styleguide');
```

Which produces something like:

```
443 files updated, 0 skipped, 0 removed
Generated in 1.432264 seconds
```

To get a full report of style guide file changes, use the `verbose()` method of the report:

```
print $styleguide->generate('/path/to/styleguide')->verbose();
```

```
...
index.html
  Updated (0.60 ms)
styleguide/data/patternlab-data.js
  Updated (1.41 ms)
annotations/annotations.js
  Updated (0.52 ms)
latest-change.txt
  Updated (0.18 ms)

443 files updated, 0 skipped, 0 removed
Generated in 1.432264 seconds
```

Validating template content
---------------------------

[](#validating-template-content)

Labcoat can use [pattern data files](http://patternlab.io/docs/data-pattern-specific.html) to validate classes that will represent live content in production environments.

For example, a template named `molecules-event` could have the following data file:

```
{
  "event": {
    "name": "Company picnic",
    "date": "August 25",
    "time": "1:00pm",
    "private": true
  }
}
```

In production, the `event` variable will be an instance of the `Event` class. This class has properties and methods that [Twig will treat like attributes of the variable](http://twig.sensiolabs.org/doc/templates.html#variables).

```
class Event {
  public $name;
  public function getDate() ...
  public function isPrivate() ...
}
```

Labcoat provides test methods to ensure that the `Event` class has all the attributes of `event` which are present in the data file.

```
class EventTest extends Labcoat\Testing\TestCase {
  public function testEvent() {
    $labcoat = new Labcoat\PatternLab("/path/to/patternlab");
    $this->assertPatternData($labcoat, "molecules-event#event", "Event");
  }
}
```

When this test is run, the output will be something like this:

```
There was 1 failure:

1) EventTest::testEvent
Failed asserting that the data classes contain the required pattern variables.

molecules-event#event.name
  FOUND: Event::$name
molecules-event#event.date
  FOUND: Event::getDate(), line 15
molecules-event#event.time
  NOT FOUND
molecules-event#event.private
  FOUND: Event::isPrivate(), line 22

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~52 days

Recently: every ~77 days

Total

8

Last Release

3458d ago

Major Versions

v1.0.2 → v2.0.0-alpha2016-03-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1526991?v=4)[pixo](/maintainers/pixo)[@pixo](https://github.com/pixo)

---

Top Contributors

[![mattsharkey](https://avatars.githubusercontent.com/u/5148918?v=4)](https://github.com/mattsharkey "mattsharkey (2 commits)")[![di5abled](https://avatars.githubusercontent.com/u/3001470?v=4)](https://github.com/di5abled "di5abled (1 commits)")[![spinnadmin](https://avatars.githubusercontent.com/u/7780045?v=4)](https://github.com/spinnadmin "spinnadmin (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pixo-labcoat/health.svg)

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

###  Alternatives

[lullabot/drainpipe

An automated build tool to allow projects to have a set standardized operations scripts.

41716.4k2](/packages/lullabot-drainpipe)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)

PHPackages © 2026

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