PHPackages                             phug/component - 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. phug/component

ActiveLibrary[Templating &amp; Views](/categories/templating)

phug/component
==============

Extension for pug-php and phug to use components in templates

1.2.1(2mo ago)436.7k↓35%3MITPHPPHP &gt;=7.2CI passing

Since Jan 7Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/phug-php/component)[ Packagist](https://packagist.org/packages/phug/component)[ Docs](http://phug-lang.com)[ GitHub Sponsors](https://github.com/kylekatarnls)[ Fund](https://opencollective.com/pug-php)[ RSS](/packages/phug-component/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (9)Versions (10)Used By (3)

Phug Component
==============

[](#phug-component)

Extension for Pug-php and Phug to use components in templates

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

[](#installation)

```
composer require phug/component

```

Enable it globally:

```
\Phug\Component\ComponentExtension::enable();
```

To enable it automatically when calling static methods `render`, `renderFile`, `display`, `displayFile` etc. on either `\Pug\Facade` or `\Phug\Phug` class.

If using in a `\Pug\Pug` or `\Phug\Renderer` instance, add the `ComponentExtension`class to modules:

```
$pug = new \Pug\Pug([/*options*/]);
\Phug\Component\ComponentExtension::enable($pug);
```

Usage
-----

[](#usage)

```
//- Register a component
component alert
  .alert.alert-danger
    .alert-title
      slot title

    slot

section
  //- Somewhere later in your template
  +alert
    slot title
      | Hello #[em world]!

    p This is an alert!
```

Output:

```

      Hello world!

    This is an alert!

```

### Default slots

[](#default-slots)

```
component page
  header
    slot header
      | Default header

  slot

  footer
    slot footer
      | Default footer

+page
  | My page content

  slot footer
    | Custom footer
```

Output:

```

  Default header

My page content

  Custom footer

```

### Parameters

[](#parameters)

Component inherit mixin behavior.

Parameters can be passed as in mixins:

```
component page($title)
  header
    h1=$title

  slot

  footer
    slot footer
      | Footer of #{$title} page

+page("Contact")
  | Contact us
```

(`$title` becomes `title` if you use pug-php or js-phpize)

Output:

```

    Contact

Contact us

  Footer of Contact page

```

### Fallback component

[](#fallback-component)

This package also include a function to get the first defined mixin/component among given names:

```
component page
  | Page component

+#{$firstComponent('customPage', 'page')}
```

Output:

```
Page component
```

And if `customPage` component is defined, it will be used instead:

```
component page
  | Page component

component customPage
  | CustomPage component

+#{$firstComponent('customPage', 'page')}
```

Output:

```
CustomPage component
```

(`$firstComponent` becomes `firstComponent` if you use pug-php or js-phpize) `$firstMixin` is also available as an alias.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance88

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community14

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

Every ~323 days

Recently: every ~562 days

Total

8

Last Release

60d ago

### Community

Maintainers

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

---

Top Contributors

[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (37 commits)")

---

Tags

htmlcomponentpugphug

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phug-component/health.svg)

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

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.6k34.7M186](/packages/phpoffice-phpword)[phug/phug

Pug (ex-Jade) facade engine for PHP, HTML template engine structured by indentation

67292.2k13](/packages/phug-phug)[pug-php/pug

HAML-like template engine for PHP

393383.2k54](/packages/pug-php-pug)[twig/string-extra

A Twig extension for Symfony String

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

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7526.3M230](/packages/laminas-laminas-view)

PHPackages © 2026

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