PHPackages                             bayfrontmedia/veil - 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. bayfrontmedia/veil

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

bayfrontmedia/veil
==================

A fast, lightweight, framework-agnostic PHP template engine.

v2.2.0(3mo ago)21.4k↓100%12MITPHPPHP ^8.0

Since Aug 18Pushed 3mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (13)Used By (2)

Veil
----

[](#veil)

A fast, lightweight, framework-agnostic PHP template engine.

Although there are some respectable, well-known PHP template engines available, most of them can be extremely complex and include a great deal of customized syntax to learn. In addition, using proprietary libraries to perform simple functions and iterations can introduce unnecessary complexity and overhead, especially since PHP is a templating language in and of itself.

While it may not be suitable for every outlying case, Veil has been created to provide minimal and rapid template language functionality, including template inheritance, in a simple framework-agnostic library.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)

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

[](#installation)

```
composer require bayfrontmedia/veil

```

Usage
-----

[](#usage)

### Start using Veil

[](#start-using-veil)

Default configuration:

```
use Bayfront\Veil\FileNotFoundException;
use Bayfront\Veil\Veil;

$options = [
    'base_path' => '', // Path to template files (no trailing slash)
    'file_extension' => '.veil.php' // Template file extensions (starting with ".")
];

$veil = new Veil($options);

```

### Working with content

[](#working-with-content)

#### Template tags

[](#template-tags)

A variety of template tags can be used with Veil. This allows for functionality such as template inheritance (chaining files), injection of content, and usage of passed parameters.

The following template tags can be used in HTML and view files:

TagFunction`@use:path/from/base`Adds contents of another file`@markdown:path/from/base`Adds markdown of another file as HTML (see [markdown](#markdown))`@inject:type`Injects content (see [inject](#inject))`@section:name`Defines a section to be placed in a view (see [sections](#sections))`@place:name`Places a defined section into the view (see [sections](#sections))`?@place:name`Places an optionally defined section into the view (see [sections](#sections))`{{-- Comment —-}}`Everything inside comment tags will be ignored and removed`{{parameter.name}}`Replaced with escaped value from the `$data` array in dot notation`{{!parameter.name}}`Replaced with unescaped (raw) value from the `$data` array in dot notation`@hasData:`Everything inside only visible if data contains key in dot notation`@hasAnyData:`Everything inside only visible if data contains at least one key in dot notation`@hasAllData:`Everything inside only visible if data contains all keys in dot notation`@dataEquals:`Everything inside only visible if string value of data key in dot notation equals case-sensitive value`@dataNotEquals:`Everything inside only visible if string value of data key in dot notation does not equal case-sensitive value`{{parameter.name||default}}`Replaced with escaped value from the `$data` array in dot notation or default value if not existing [\*](#note)`{{!parameter.name||default}}`Replaced with unescaped (raw) value from the `$data` array in dot notation or default value if not existing [\*](#note)> ##### Note:
>
> [](#note)
>
> The default value can be either a plaintext string, or another key on the `$data` array in dot notation.

**Examples:**

```
@hasData:nested.key
Content only visible if data contains "nested.key".
@endHasData

@hasAnyData:key|nested.key
Content only visible if data contains "key" or "nested.key".
@endHasAnyData

@hasAllData:key|nested.key
Content only visible if data contains "key" and "nested.key".
@endHasAllData

@dataEquals:nested.key|value
Content only visible if data key "nested.key" exists and has case-sensitive value "value".
@endDataEquals

@dataNotEquals:nested.key|value
Content only visible if data key "nested.key" does not exist or does not have case-sensitive value "value".
@endDataNotEquals
```

##### Sections

[](#sections)

Sections are used to define a block of HTML using the `@section` tag, which is placed in a view using the `@place` tag.

**Example `pages/index`:**

```
@section:head

    html {
        font-family: 'Open Sans', sans-serif;
    }

@endsection

@section:content

Welcome, {{name}}!

This is some content.

@endsection

@use:layouts/default
```

**Example `layouts/default`:**

```
>

    {{title}}

    @place:head

    {{title}}

    @place:content

    @use:layouts/partials/sidebar

    @use:layouts/partials/footer

?@place:end_body

```

In the examples above, the sections `head` and `content` are defined in `pages/index`, then placed in `layouts/default`.

In addition, an optional `end_body` section is placed before the closing `body` tag.

#### Raw PHP

[](#raw-php)

View files can directly access the `$data` array in raw PHP. In fact, any other PHP code can be directly embedded in any view file. However, this should be kept to simple tasks such as performing loop iterations. Frequently embedding raw PHP from your view may be a sign you have too much logic within the template.

### Public methods

[](#public-methods)

- [getBasePath](#getbasepath)
- [setBasePath](#setbasepath)
- [inject](#inject)
- [getHtml](#gethtml)
- [html](#html)
- [getView](#getview)
- [view](#view)
- [minify](#minify)
- [markdown](#markdown)

---

### getBasePath

[](#getbasepath)

**Description:**

Returns base path.

**Parameters:**

- (None)

**Returns:**

- (string)

---

### setBasePath

[](#setbasepath)

**Description:**

Sets base path.

**Parameters:**

- `$base_path` (string)

**Returns:**

- (void)

---

### inject

[](#inject)

**Description:**

Add injectable(s) by their respective types.

Default injectable types to use in your templates include:

- `css`: Wraps content into a CSS `` element
- `js`: Wraps content into a `` element
- `head`: Insert content into the `` section
- `end_body`: Insert content just before the `` tag

In addition to the default injectable types, custom types can be added and used.

**NOTE:** If `$content` is an array, all injectables will share the same priority.

**Parameters:**

- `$type` (string)
- `$content` (string|array)
- `$priority = 5` (int): Injectables of the same type will be injected in order of priority

**Returns:**

- (self)

**Example:**

```
$veil->inject('js', 'javascript-file.js');

```

Using the above example, whenever the `@inject:js` template tag appears, it will be replaced with:

```

```

---

### getHtml

[](#gethtml)

**Description:**

Get compiled HTML as a string.

**Parameters:**

- `$html` (string)
- `$data = []` (array): Data to pass to HTML
- `$minify = false` (bool): Minify compiled HTML? See [minify](#minify) for more info.

**Returns:**

- (string)

**Throws:**

- `Bayfront\Veil\FileNotFoundException`

**Example:**

```
$html = 'Hello, {{name}}! Please visit: example.com.';

try {

    $html = $veil->getHtml($html, ['name' => 'John']);

} catch (FileNotFoundException $e) {

    http_response_code(404);

    die($e->getMessage());

}

```

---

### html

[](#html)

**Description:**

Echo compiled HTML.

**Parameters:**

- `$html` (string)
- `$data = []` (array): Data to pass to HTML
- `$minify = false` (bool): Minify compiled HTML? See [minify](#minify) for more info.

**Returns:**

- (void)

**Throws:**

- `Bayfront\Veil\FileNotFoundException`

**Example:**

```
$html = 'Hello, {{name}}! Please visit: example.com.';

try {

    $veil->html($html, ['name' => 'John']);

} catch (FileNotFoundException $e) {

    http_response_code(404);

    die($e->getMessage());

}

```

---

### getView

[](#getview)

**Description:**

Get compiled template file as a string.

**Parameters:**

- `$file` (string): Path to file from base path, excluding file extension
- `$data = []` (array): Data to pass to view
- `$minify = false` (bool): Minify compiled HTML? See [minify](#minify) for more info.

**Returns:**

- (string)

**Throws:**

- `Bayfront\Veil\FileNotFoundException`

**Example:**

```
try {

    $html = $veil->getView('/path/to/file', ['name' => 'John']);

} catch (FileNotFoundException $e) {

    http_response_code(404);

    die($e->getMessage());

}

```

---

### view

[](#view)

**Description:**

Echo compiled template file.

**Parameters:**

- `$file` (string): Path to file from base path, excluding file extension
- `$data = []` (array): Data to pass to view
- `$minify = false` (bool): Minify compiled HTML? See [minify](#minify) for more info.

**Returns:**

- (void)

**Throws:**

- `Bayfront\Veil\FileNotFoundException`

**Example:**

```
try {

    $veil->view('/path/to/file', ['name' => 'John']);

} catch (FileNotFoundException $e) {

    http_response_code(404);

    die($e->getMessage());

}

```

---

### minify

[](#minify)

**Description:**

Minify HTML.

Currently, Veil uses [Tiny Html Minifier](https://github.com/pfaciana/tiny-html-minifier) for this method.

**NOTE:** In some cases, HTML may not minify correctly, so use with caution. It is recommended you test this with your HTML and views before using in production.

**Parameters:**

- `$html` (string)

**Returns:**

- (string)

**Example:**

See [markdown](#markdown).

---

### markdown

[](#markdown)

**Description:**

Convert Markdown syntax to HTML.

Currently, Veil uses [Parsedown](https://github.com/erusev/parsedown) for this method.

**Parameters:**

- `$markdown` (string)

**Returns:**

- (string)

**Example:**

Convert a view file containing markdown to minified HTML:

```
try {

    $md = $veil->getView('path/to/markdown');

} catch (FileNotFoundException $e) {

    http_response_code(404);
    die('View not found!');

}

echo $veil->minify($veil->markdown($md));

```

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance85

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

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

Recently: every ~272 days

Total

12

Last Release

111d ago

Major Versions

v1.4.0 → v2.0.02023-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (33 commits)")

---

Tags

enginehtmlmarkdownminifyphptemplateviewphphtmlminifymarkdowntemplateviewengine

### Embed Badge

![Health badge](/badges/bayfrontmedia-veil/health.svg)

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

PHPackages © 2026

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