PHPackages                             gajus/brick - 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. gajus/brick

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

gajus/brick
===========

PHP template system that's fast, easy to use and easy to extend.

2.1.0(11y ago)1246BSD-3-ClausePHPPHP &gt;=5.4

Since Nov 25Pushed 11y ago2 watchersCompare

[ Source](https://github.com/gajus/brick)[ Packagist](https://packagist.org/packages/gajus/brick)[ Docs](https://github.com/gajus/brick)[ RSS](/packages/gajus-brick/feed)WikiDiscussions master Synced 3d ago

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

Brick
=====

[](#brick)

[![Build Status](https://camo.githubusercontent.com/a34b7e9b5e5627c577eb2712fe14ec8c561d35404666c22afaa14630e2f1ab9e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f67616a75732f627269636b2f6d61737465722e737667)](https://travis-ci.org/gajus/strading)[![Coverage Status](https://camo.githubusercontent.com/68ec23222c14349be9427a27d1cc0fa21d6ce28de738a49ae3256a5552160553/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f67616a75732f627269636b2f6d61737465722e737667)](https://coveralls.io/r/gajus/strading?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/38c54900909afbc3f899d4315aaecf980aca9c6a0b927de375c83917a01130d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67616a75732f627269636b2e737667)](https://packagist.org/packages/gajus/strading)

PHP template system that's fast, easy to use and easy to extend.

- Plain PHP, no new syntax to learn.
- Framework-agnostic, will work with any project.

About Brick
-----------

[](#about-brick)

> Brick is not a template engine that would lex/parse template as a string (think Twig).
>
> Some of you might remember Chad Minick's article "[Simple PHP Template Engine](http://chadminick.com/articles/simple-php-template-engine.html)" (2009; Has it been that long?). I have been using a variation of an abstraction following the principles outlined in Chad's article for a long time. Brick is the final of the gang. I am happy with the API, I am happy with the inheritance rules, scope definition; it is perfect!
>
> I am using Brick in several freelance projects and I am making it open to others. I am looking for people who share the same mindset about what template processing in PHP should be. Contributors and critique is welcome.

–

Features
--------

[](#features)

- Handles not found template files
- Protects from [directory traversal attacks](http://en.wikipedia.org/wiki/Directory_traversal_attack) (at the template inclusion level)
- Isolates template execution scope

The following examples together with the included [unit tests](https://github.com/gajus/brick/tree/master/tests) will set you going. Please [raise an issue](https://github.com/gajus/brick/issues) if you feel that there are bits that need to be clarified.

Overview
--------

[](#overview)

### System

[](#system)

`System` class is responsible for template resolution and scope management.

Public methods:

- [setDirectory](https://github.com/gajus/brick/blob/master/src/System.php)
- [getDirectory](https://github.com/gajus/brick/blob/master/src/System.php)
- [setGlobals](https://github.com/gajus/brick/blob/master/src/System.php)
- [getGlobals](https://github.com/gajus/brick/blob/master/src/System.php)
- [setTemplateExtension](https://github.com/gajus/brick/blob/master/src/System.php)
- [getTemplateExtension](https://github.com/gajus/brick/blob/master/src/System.php)
- [view](https://github.com/gajus/brick/blob/master/src/System.php)
- [template](https://github.com/gajus/brick/blob/master/src/System.php)

### Subsystem

[](#subsystem)

`Subsystem` class is responsible for template resolution and scope management.

Views that are built using an instance of `System` will be using `Subsystem` to produce inner views. This restricts a template access to controlling the globals and other sensitive variables.

Public methods:

- [view](https://github.com/gajus/brick/blob/master/src/Subsystem.php)

### Template

[](#template)

`Template` class is responsible for isolating template execution scope, extracting scope variables and capturing the output buffer.

Public methods:

- [render](https://github.com/gajus/brick/blob/master/src/Template.php)

Getting Started
---------------

[](#getting-started)

### Producing a View

[](#producing-a-view)

```
// Set the absolute path to the folder containing templates.
$system = new \Gajus\Brick\System(__DIR__ . '/templates');
// Refer to the template using a path relative to the template folder.
echo $system->view('foo');
```

Template file must have a ".php" extension. When referring to templates, do not include the file extension. You can change the name of the extension:

```
$system->setTemplateExtension('.tpl.php');
```

#### View Scope

[](#view-scope)

- `$system` an instance of `Subsystem`.
- `$globals` variables shared across all views produced by the same instance of `System`.
- Variables assigned to the view at the time of producing the view.

### Assigning Variables

[](#assigning-variables)

Scope variables are extracted to the execution context of the template, i.e. template can access them as regular variables.

```
// template_that_is_using_foo_variable.php
$foo;
```

Scope variables are assigned at the time of producing a view.

```
$system->view('template_that_is_using_foo_variable', ['foo' => 'bar']); // 'bar'
```

### Globals

[](#globals)

Views produced using the same instance of the `System` have access to a `$globals` variables.

```
$system->getGlobals(['foo' => 'bar']);
$system->view('template_that_is_using_foo_variable'); // 'bar'
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

4189d ago

Major Versions

1.0.0 → 2.0.02014-11-25

### Community

Maintainers

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

---

Top Contributors

[![gajus](https://avatars.githubusercontent.com/u/973543?v=4)](https://github.com/gajus "gajus (65 commits)")

---

Tags

template

### Embed Badge

![Health badge](/badges/gajus-brick/health.svg)

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

###  Alternatives

[phpoffice/phpword

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

7.5k34.7M186](/packages/phpoffice-phpword)[rize/uri-template

PHP URI Template (RFC 6570) supports both expansion &amp; extraction

420137.3M46](/packages/rize-uri-template)[mopa/bootstrap-sandbox-bundle

Seperate live docs from code

256.8k](/packages/mopa-bootstrap-sandbox-bundle)[larablocks/pigeon

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

143.7k](/packages/larablocks-pigeon)

PHPackages © 2026

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