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

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

fyre/view
=========

A template rendering library.

v11.0.2(9mo ago)0184↓83.3%13MITPHP

Since Dec 27Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreView)[ Packagist](https://packagist.org/packages/fyre/view)[ RSS](/packages/fyre-view/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (14)Versions (48)Used By (3)

FyreView
========

[](#fyreview)

**FyreView** is a free, open-source template rendering library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Layouts](#layouts)
- [Cells](#cells)
- [Elements](#elements)
- [Blocks](#blocks)
- [Template Locator](#template-locator)
- [Cell Registry](#cell-registry)
- [Helper Registry](#helper-registry)
- [Helpers](#helpers)
    - [CSP](#csp)
    - [Form](#form)
    - [Format](#format)
    - [Url](#url)

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

[](#installation)

**Using Composer**

```
composer require fyre/view

```

In PHP:

```
use Fyre\View\View;
```

Basic Usage
-----------

[](#basic-usage)

- `$templateLocator` is a [*TemplateLocator*](#template-locator).
- `$helperRegistry` is a [*HelperRegistry*](#helper-registry).
- `$cellRegistry` is a [*CellRegistry*](#cell-registry).
- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

```
$view = new View($templateLocator, $helperRegistry, $cellRegistry, $request);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$view = $container->use(View::class);
```

Methods
-------

[](#methods)

**Get Data**

Get the view data.

```
$data = $view->getData();
```

**Get Layout**

Get the layout.

```
$layout = $view->getLayout();
```

**Get Request**

Get the [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

```
$request = $view->getRequest();
```

**Load Helper**

Load a [*Helper*](#helpers).

- `$name` is a string representing the helper name.
- `$options` is an array containing helper options.

```
$helper = $view->loadHelper($name, $options);
```

**Render**

Render a template.

- `$file` is a string representing the template file.

```
echo $view->render($file);
```

Templates files must end in the extension `.php`, and must exist in one of the defined [*TemplateLocator*](#template-locator) paths.

**Set Data**

Set view data.

- `$data` is an array containing data to pass to the template.

```
$view->setData($data);
```

**Set Layout**

Set the layout.

- `$layout` is a string representing the layout file.

```
$view->setLayout($layout);
```

Layout files must end in the extension `.php`, and must exist in a "*layouts*" folder in one of the defined [*TemplateLocator*](#template-locator) paths.

### Layouts

[](#layouts)

You can use layouts when rendering views by placing a `default.php` file in a *layouts* folder of one of the defined [*TemplateLocator*](#template-locator) paths. You can create multiple layouts, and specify the layout to use with the `setLayout` method above.

The rendered content is passed to the layout file via the `content` method of `$this`. Any other defined data is also passed to the layout.

```
$this->content();
```

Cells
-----

[](#cells)

Custom cells can be created by extending `\Fyre\View\Cell`, and suffixing the class name with "*Cell*".

**Cell**

Render a *Cell*.

- `$cell` is a string, and can either represent the cell name (implementing a `display` method) or in the format of "*Cell::method*".
- `$args` is an array of arguments that will be passed to the cell method, and will default to *\[\]*.

```
echo $this->cell($cell, $args);
```

Cell classes must exist in a namespace that will be loaded by the [*CellRegistry*](#cell-registry).

Elements
--------

[](#elements)

**Element**

Render an element.

- `$file` is a string representing the element file.
- `$data` is an array containing data to pass to the element, and will default to *\[\]*.

```
echo $this->element($file, $data);
```

Element files must end in the extension `.php`, and must exist in an "*elements*" folder in one of the defined [*TemplateLocator*](#template-locator) paths.

Blocks
------

[](#blocks)

**Append**

Append content to a block.

- `$name` is a string representing the block name.

```
$this->append($name);
```

Any output until the block is ended will be appended to the block.

**Assign**

Assign content to a block.

- `$name` is a string representing the block name.
- `$content` is a string representing the content.

```
$this->assign($name, $content);
```

**End**

End a block.

```
$this->end();
```

**Fetch**

Fetch a block.

- `$name` is a string representing the block name.
- `$default` is a string representing the default value, and will default to "".

```
$block = $this->fetch($name, $default);
```

**Prepend**

Prepend content to a block.

- `$name` is a string representing the block name.

```
$this->prepend($name);
```

Any output until the block is ended will be prepended to the block.

**Reset**

Reset content of a block.

- `$name` is a string representing the block name.

```
$this->reset($name);
```

**Start**

- `$name` is a string representing the block name.

Start content for a block.

```
$this->start($name);
```

Template Locator
----------------

[](#template-locator)

```
use Fyre\View\TemplateLocator;
```

```
$templateLocator = new TemplateLocator();
```

**Autoloading**

It is recommended to bind the *TemplateLocator* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(TemplateLocator::class);
```

### Template Locator Methods

[](#template-locator-methods)

**Add Path**

Add a path for loading templates.

- `$path` is a string representing the path.

```
$templateLocator->addPath($path);
```

**Get Paths**

Get the paths.

```
$paths = $templateLocator->getPaths();
```

**Locate**

Find a file in paths.

- `$file` is a string representing the file name.
- `$folder` is a string representing the folder name, and will default to "".

```
$filePath = $templateLocator->findFile($file, $folder);
```

**Remove Path**

- `$path` is a string representing the path.

```
$templateLocator->removePath($path);
```

### Template Locator Static Methods

[](#template-locator-static-methods)

**Normalize**

Normalize a template file name.

- `$string` is a string representing the file name.

```
$normalized = TemplateLocator::normalize($string);
```

Cell Registry
-------------

[](#cell-registry)

```
use Fyre\View\CellRegistry;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$cellRegistry = new CellRegistry($container);
```

**Autoloading**

It is recommended to bind the *CellRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(CellRegistry::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$cellRegistry = $container->use(CellRegistry::class);
```

### Cell Registry Methods

[](#cell-registry-methods)

**Add Namespace**

Add a namespace for automatically loading cells.

- `$namespace` is a string representing the namespace.

```
$cellRegistry->addNamespace($namespace);
```

**Build**

Build a cell.

- `$name` is a string representing the cell name.
- `$view` is a *View*.
- `$options` is an array containing cell options.

```
$cell = $cellRegistry->build($name, $view, $options);
```

**Clear**

Clear all namespaces and cells.

```
$cellRegistry->clear();
```

**Find**

Find a cell class.

- `$name` is a string representing the cell name.

```
$className = $cellRegistry->find($name);
```

**Get Namespaces**

Get the namespaces.

```
$namespaces = $cellRegistry->getNamespaces();
```

**Has Namespace**

Check if a namespace exists.

- `$namespace` is a string representing the namespace.

```
$hasNamespace = $cellRegistry->hasNamespace($namespace);
```

**Remove Namespace**

Remove a namespace.

- `$namespace` is a string representing the namespace.

```
$cellRegistry->removeNamespace($namespace);
```

Helper Registry
---------------

[](#helper-registry)

```
use Fyre\View\HelperRegistry;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$helperRegistry = new HelperRegistry($container);
```

**Autoloading**

It is recommended to bind the *HelperRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(HelperRegistry::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$helperRegistry = $container->use(HelperRegistry::class);
```

### Helper Registry Methods

[](#helper-registry-methods)

**Add Namespace**

Add a namespace for automatically loading helpers.

- `$namespace` is a string representing the namespace.

```
$helperRegistry->addNamespace($namespace);
```

**Build**

Build a helper.

- `$name` is a string representing the helper name.
- `$view` is a *View*.
- `$options` is an array containing helper options.

```
$helper = $helperRegistry->build($name, $view, $options);
```

**Clear**

Clear all namespaces and helpers.

```
$helperRegistry->clear();
```

**Find**

Find a helper class.

- `$name` is a string representing the helper name.

```
$className = $helperRegistry->find($name);
```

**Get Namespaces**

Get the namespaces.

```
$namespaces = $helperRegistry->getNamespaces();
```

**Has Namespace**

Check if a namespace exists.

- `$namespace` is a string representing the namespace.

```
$hasNamespace = $helperRegistry->hasNamespace($namespace);
```

**Remove Namespace**

Remove a namespace.

- `$namespace` is a string representing the namespace.

```
$helperRegistry->removeNamespace($namespace);
```

Helpers
-------

[](#helpers)

Helpers can be used inside of templates or elements using the class name as a property of `$this`.

```
$helper = $this->MyHelper;
```

Alternatively, you can load a helper with configuration options using the `loadHelper` method of the *View*.

Custom helpers can be created by extending `\Fyre\View\Helper`, suffixing the class name with "*Helper*", and ensuring the `__construct` method accepts *View* as the argument (and optionally an `$options` array as the second parameter).

**Get Config**

Get the configuration options.

```
$config = $helper->getConfig();
```

**Get View**

Get the *View*.

```
$view = $helper->getView();
```

### CSP

[](#csp)

The CSP helper allows an easy way to generate nonces, and automatically add them to your [*CSP*](https://github.com/elusivecodes/FyreCSP) policies.

**Script Nonce**

Generate a script nonce.

```
$nonce = $this->CSP->scriptNonce();
```

**Style Nonce**

Generate a style nonce.

```
$nonce = $this->CSP->styleNonce();
```

### Form

[](#form)

**Button**

Render a button element.

- `$content` is a string representing the button content.
- `$options` is an array of options for rendering the button.

```
$button = $this->Form->button($content, $options);
```

By default, the button content will be HTML escaped. To disable this, set the `escape` value to *false* in the `options` array.

All other `options` will be created as attributes on the button element.

**Close**

Render a form close tag.

```
$close = $this->Form->close();
```

**Fieldset Close**

Render a fieldset close tag.

```
$fieldsetClose = $this->Form->fieldsetClose();
```

**Fieldset Open**

Render a fieldset open tag.

- `$options` is an array of options for rendering the fieldset.

```
$fieldset = $this->Form->fieldsetOpen($options);
```

All `options` will be created as attributes on the fieldset element.

**Input**

Render an input element.

- `$key` is a string representing the field key, using dot notation.
- `$options` is an array of options for rendering the label.

```
$input = $this->Form->input($key, $options);
```

All `options` will be created as attributes on the input element.

- The default `id` and `name` attributes will be converted from the field key.
- The input `type` and other default attributes will be determined from the [*Table*](https://github.com/elusivecodes/FyreSchema#tables) and [*Model Validation*](https://github.com/elusivecodes/FyreORM#validation).
- The default value will be retrieved from the [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests) `$_POST` data or form context.
    - If the form was opened in an [*Entity*](https://github.com/elusivecodes/FyreEntity) context, the [*Entity*](https://github.com/elusivecodes/FyreEntity) and the [*Table*](https://github.com/elusivecodes/FyreSchema#tables) will also be used.
- Select options can be specified using the `options` key.
- Checkboxes and radio inputs can be marked as checked by setting the `checked` option to *true*.
- Multiple select menus will (by default) render a hidden field with an empty value. This can be disabled by setting the `hiddenField` option to *false*.
- Checkboxes will (by default) render a hidden field with the value "0". This can be disabled by setting the `hiddenField` option to *false*.

You can also use the following helper methods to generate specific input type fields.

```
$input = $this->Form->checkbox($key, $options);
$input = $this->Form->color($key, $options);
$input = $this->Form->date($key, $options);
$input = $this->Form->datetime($key, $options);
$input = $this->Form->email($key, $options);
$input = $this->Form->file($key, $options);
$input = $this->Form->hidden($key, $options);
$input = $this->Form->image($key, $options);
$input = $this->Form->month($key, $options);
$input = $this->Form->number($key, $options);
$input = $this->Form->password($key, $options);
$input = $this->Form->radio($key, $options);
$input = $this->Form->range($key, $options);
$input = $this->Form->reset($key, $options);
$input = $this->Form->search($key, $options);
$input = $this->Form->select($key, $options);
$input = $this->Form->selectMulti($key, $options);
$input = $this->Form->submit($key, $options);
$input = $this->Form->tel($key, $options);
$input = $this->Form->text($key, $options);
$input = $this->Form->time($key, $options);
$input = $this->Form->url($key, $options);
$input = $this->Form->week($key, $options);
```

**Label**

Render a label element.

- `$key` is a string representing the field key.
- `$options` is an array of options for rendering the label.

```
$label = $this->Form->label($key, $options);
```

The label text will be retrieved from the [*Lang*](https://github.com/elusivecodes/FyreLang) using the `Field.{field_name}` key or converted from the field name. You can also set custom label text by setting the `text` option.

By default, the label content will be HTML escaped. To disable this, set the `escape` value to *false* in the `options` array.

All other `options` will be created as attributes on the label element. The default `for` attribute will be converted from the field key.

**Legend**

Render a legend element.

- `$content` is a string representing the legend content.
- `$options` is an array of options for rendering the legend.

```
$legend = $this->Form->legend($content, $options);
```

By default, the legend content will be HTML escaped. To disable this, set the `escape` value to *false* in the `options` array.

All other `options` will be created as attributes on the legend element.

**Open**

Render a form open tag.

- `$item` is an [*Entity*](https://github.com/elusivecodes/FyreEntity) or other (supported) object representing the form context, and will default to *null*
- `$options` is an array of options for rendering the form.

```
$open = $this->Form->open($item, $options);
```

All `options` will be created as attributes on the form element.

**Open Multipart**

Render a multipart form open tag.

- `$item` is an array or object representing the form context, and will default to *null*
- `$options` is an array of options for rendering the form.

```
$open = $this->Form->openMultipart($item, $options);
```

All `options` will be created as attributes on the form element.

### Format

[](#format)

The format helper provides a convenient wrapper for [*Formatter*](https://github.com/elusivecodes/FyreFormatter) methods.

### Url

[](#url)

The URL helper provides methods for generating [*Router*](https://github.com/elusivecodes/FyreRouter) links.

**Link**

Generate an anchor link for a destination.

- `$content` is a string representing the link content.
- `$options` is an array containing options.
    - `escape` is a boolean indicating whether to escape the link content, and will default to *true*.
    - `fullBase` is a boolean indicating whether to use the full base URI, and will default to *false*.

```
$link = $this->Url->link($content, $options);
```

**Path**

Generate a url for a relative path.

- `$path` is a string representing the file path.
- `$options` is an array containing options.
    - `fullBase` is a boolean indicating whether to use the full base URI, and will default to *false*.

```
$url = $this->Url->path($path, $options);
```

**To**

Generate a url for a named route.

- `$name` is a string representing the route alias.
- `$arguments` is an array containing the route arguments.
    - `?` is an array containing route query parameters.
    - `#` is a string representing the fragment component of the URI.
- `$options` is an array containing options.
    - `fullBase` is a boolean indicating whether to use the full base URI, and will default to *false*.

```
$url = $this->Url->to($destination, $options);
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance58

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 87% 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 ~29 days

Total

47

Last Release

276d ago

Major Versions

v6.1.4 → v7.02024-06-07

v7.1.0 → v8.02024-10-09

v8.0 → v9.02024-10-11

v9.0.1 → v10.02024-12-08

v10.1.11 → v11.02025-09-19

### Community

Maintainers

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

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (40 commits)")[![pm-michael](https://avatars.githubusercontent.com/u/49225527?v=4)](https://github.com/pm-michael "pm-michael (6 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3861.2M](/packages/limenius-react-bundle)[area17/laravel-auto-head-tags

Laravel Auto Head Tags helps you build the list of head elements for your app

4616.0k](/packages/area17-laravel-auto-head-tags)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.2k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

291.8k](/packages/webkinder-sproutset)[awkwardideas/switchblade

Extended blade directives for laravel

102.1k](/packages/awkwardideas-switchblade)

PHPackages © 2026

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