PHPackages                             brickhouse/view-engine - 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. brickhouse/view-engine

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

brickhouse/view-engine
======================

Frontend functionality for Brickhouse

071PHPCI failing

Since Jan 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/brickhouse-php/view-engine)[ Packagist](https://packagist.org/packages/brickhouse/view-engine)[ RSS](/packages/brickhouse-view-engine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Brickhouse View Engine
======================

[](#brickhouse-view-engine)

This library is a templating engine for PHP applications. It has taken inspiration from [Blade](https://laravel.com/docs/11.x/blade), [Vue](https://vuejs.org) and [Tempest](https://github.com/tempestphp/tempest-framework).

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

[](#installation)

To install the library, you need to require the package via composer:

```
composer require brickhouse/view-engine
```

Usage
-----

[](#usage)

To compile and render views, you need to create a resolver for views:

```
use Brickhouse\View\Engine\Engine;

$resolver = new ViewResolver(basePath: __DIR__);
$renderer = new Renderer($resolver);
```

The `basePath` parameter to `ViewResolver` determines where the resolver will look for layouts, components and views. Depending on the type being resolved, the resolver will look in these directories:

TypePath (relative to `basePath`)Views`views/`Layouts`views/layouts/`Components`views/components/`The renderer can then be used to compile and render templates into HTML:

```
$rendered = $renderer->render('Hello, Max.');

// or...

$rendered = $renderer->renderFile('/path/to/view');
```

### Displaying data

[](#displaying-data)

You can use the renderer to interpolate content in the template. You can do so by wrapping the variable in curly braces:

```
$template = 'Hello, {{ $name }}.';
$rendered = $renderer->render($template, ['name' => 'Max']);
```

The template will then render as:

```
Hello, Max.
```

You can also display the results of any PHP function - or really any PHP code:

```
$template = 'UNIX Time: {{ time() }}';
$rendered = $renderer->render($template);
```

### Conditions

[](#conditions)

The templating engine allows for conditions, which act on any data passed to the template. They provide a more concise way of adding conditional content to your template, without using PHP's control structures.

Conditional statements, along with other control structures, as defined using attributes:

```
There is a single row.
There is multiple rows.
There are no rows.
```

Just like interpolation, these attributes support any PHP code which can be used inside a normal `if`-statement.

### Loops

[](#loops)

In addition to conditional attributes, you can also iterate over elements in a list:

```
Row index: {{ $i }}

User ID: {{ $user->id }}
```

### Components

[](#components)

Components allow the template to re-use the same markup multiple places in your application.

You can create a component by creating a new file in the `views/components` directory, with a `.view.php` extension, such as `alert.view.php`:

```

    An error occured.

```

You can then reference the component using it's relative path, prefixed with `x-`:

```

```

#### Passing attributes

[](#passing-attributes)

A static component can only do so much, so components also support passing attributes to them, which can then be used inside of the component. For example, if we change the component to use the template:

```

    {{ $message }}

```

Then, we can pass the message using an attribute, when using it:

```

```

#### Slots

[](#slots)

You will often want to create more complex components, which needs more than just text interpolation. For this, you can use "slots", which will replace parts of the component markup. Let's take the same component as before, but use slots for it's content:

```

```

Then, when we reference the component, we can pass markup into it's body content:

```

    Error: user could not be found.

```

This will emplace the given content into the `slot`-tag and render into the following:

```

    Error: user could not be found.

```

#### Fallback / default content

[](#fallback--default-content)

You also don't need to define the content of the slot every time, if it will likely stay the same. For that, it might be better to define the default content of a slot, like so:

```

        An error occured.

```

If the component is referenced without providing the slot, `An error occured.` will be shown:

```

```

This will render the default content:

```

    An error occured.

```

But if we provide content for the slot:

```

    Warning: connection lost.

```

Then the provided content will be rendered instead:

```

    Warning: connection lost.

```

#### Named slots

[](#named-slots)

Sometimes, you need more than a single slot for a component. To facilitate that, you can use "named slots". Let's use the same `alert` component:

```

```

We have defined an additional slot named `title`. Slots are named by prefixing the name with a hashtag (`#`) as an attribute. We can then define the content of the given slot, by using `template`-tags:

```

        Could not save user.

        Error: user could not be found.

```

Here, the `template`-tag with the `#title` attribute defines the content of the `title`-slot, whereas the `template`-tag without any attributes defines the content of the default slot.

### Layouts

[](#layouts)

Views in an application often share a lot of common elements, such as navigation, headers, footers, etc. To define the common interface, you can use layouts. Layouts are defined much like components, but are stored within `views/layouts/` instead of `views/components/`:

```

>

        Application Title

```

Within the layout, we define a `slot`-tag, which defines where the view content is meant to be rendered. To use the layout, you can reference it by prefixing `x-layout::` to the layout path:

```

    Dashboard

```

### Passing attributes

[](#passing-attributes-1)

Much like components, layouts also support passing attributes:

```
>

        {{ $title ?? 'Application Title' }}

```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/89e99714610675e29eb832627ab917dabde2f35dc0246eb7c46f68d109136efc?d=identicon)[maxnatamo](/maintainers/maxnatamo)

---

Top Contributors

[![maxnatamo](https://avatars.githubusercontent.com/u/5898152?v=4)](https://github.com/maxnatamo "maxnatamo (18 commits)")

### Embed Badge

![Health badge](/badges/brickhouse-view-engine/health.svg)

```
[![Health](https://phpackages.com/badges/brickhouse-view-engine/health.svg)](https://phpackages.com/packages/brickhouse-view-engine)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

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