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

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

peacock/view
============

0.0.4(9y ago)0368proprietaryPHP

Since Jun 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/TomWright/Peacock)[ Packagist](https://packagist.org/packages/peacock/view)[ RSS](/packages/peacock-view/feed)WikiDiscussions master Synced 4w ago

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

Peacock
=======

[](#peacock)

[![Build Status](https://camo.githubusercontent.com/bf8182a655c844d2e993a6ec63c9f38a0fb8128a552529caaef3c8cecb4400f2/68747470733a2f2f7472617669732d63692e6f72672f546f6d5772696768742f506561636f636b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/TomWright/Peacock)[![Total Downloads](https://camo.githubusercontent.com/81bd14a335b5aa342226fcbff2adfad80dac15f3acb7d9c5275d5cfea0854add/68747470733a2f2f706f7365722e707567782e6f72672f706561636f636b2f766965772f642f746f74616c2e737667)](https://packagist.org/packages/peacock/view)[![Latest Stable Version](https://camo.githubusercontent.com/ce988161879b82dce149bfe1b92445b7be1824b0268cecace79766d0e678db84/68747470733a2f2f706f7365722e707567782e6f72672f706561636f636b2f766965772f762f737461626c652e737667)](https://packagist.org/packages/peacock/view)[![Latest Unstable Version](https://camo.githubusercontent.com/fee03fe1fbfb62485d7202469f4a8536a65ca59186743a1e19816975f0d40b91/68747470733a2f2f706f7365722e707567782e6f72672f706561636f636b2f766965772f762f756e737461626c652e737667)](https://packagist.org/packages/peacock/view)[![License](https://camo.githubusercontent.com/60f3125360b1be508ac7377037e33a82aaa018cb2112f43bb4fdf7c25fa42fe2/68747470733a2f2f706f7365722e707567782e6f72672f706561636f636b2f766965772f6c6963656e73652e737667)](https://packagist.org/packages/peacock/view)

Peacock is a View/Layout engine designed to make it easy to use and manipulate views without having to dive into the HTML.

Installation
============

[](#installation)

```
composer install peacock/view

```

Usage
=====

[](#usage)

Create a view file: `say_hello.php`.

```
Hello there, .

```

Get an instance of the `ViewFactory`.

```
$viewFactory = ViewFactory::getInstance();
$viewFactory->setViewsDirectory(VIEWS_PATH);

```

Get a `View` out of the `ViewFactory`.

```
$viewData = ['username' => 'Tom'];
$view = $viewFactory->view('say_hello', $viewData);

```

Render the `View`.

```
$view->render();
// Hello there, Tom.

```

Using Layouts
-------------

[](#using-layouts)

Create a layout file: `layout.php`.

```

    Example

        Example
        {RENDER_SECTION: content}

```

Create a view file: `say_hello.php`.

```
Hello there, .

```

Get a `Layout` out of the `ViewFactory`.

```
$viewData = ['username' => 'Tom'];
$layout = $viewFactory->layout('layout', $viewData);

```

Add a child view to the layout specifying that the view content should be added to the `content` section, and then render the layout.

```
$childView = $layout->childView('say_hello', 'content');
$layout->render();

```

That will give the following output.

```

    Example

        Example
        Hello there, Tom.

```

Multiple Child Views &amp; Layouts
----------------------------------

[](#multiple-child-views--layouts)

You can add the same View/Layout multiple times.

```
$childView = $layout->childView('say_hello', 'content');
$childView = $layout->childView('say_hello', 'content');
$childView = $layout->childView('say_hello', 'content');
$layout->render();

```

That will give the following output.

```

    Example

        Example
        Hello there, Tom.
        Hello there, Tom.
        Hello there, Tom.

```

View Data
---------

[](#view-data)

You can also pass data directly to a child view/layout.

```
$childView = $layout->childView('say_hello', 'content', ['username' => 'Frank']);
$childView = $layout->childView('say_hello', 'content', ['username' => 'Amelia']);
$childView = $layout->childView('say_hello', 'content', ['username' => 'Steve']);
$layout->render();

```

That will give the following output.

```

    Example

        Example
        Hello there, Frank.
        Hello there, Amelia.
        Hello there, Steve.

```

Child Layouts
-------------

[](#child-layouts)

If you want a view to add content to multiple sections then a `Layout` is the way to go.

Let's say we have a blog post that will show content in the main body, but also add the author's name to the footer.

`layout.php`

```

    {RENDER_SECTION:title} - My Blog

        {RENDER_SECTION:main_content}

        {RENDER_SECTION:footer}

```

`blog_post`

```
{SECTION:title}{END_SECTION}

{SECTION:main_content}

{END_SECTION}

{SECTION:footer}Written by {END_SECTION}

```

Implementation:

```
$post = new stdClass();
$post->title = 'How to use Peacock';
$post->author = 'Tom Wright';
$post->content = 'You should check out the GitHub README!';
$postData = ['post' => $post];

$layout = $viewFactory->layout('layout');
$layout->childLayout('blog_post', $postData);
$layout->render();

```

Output:

```

    How to use Peacock - My Blog

How to use Peacock
You should check out the GitHub README!

    Written by Tom Wright

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

3486d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/935867?v=4)[Tom Wright](/maintainers/TomWright)[@TomWright](https://github.com/TomWright)

---

Top Contributors

[![TomWright](https://avatars.githubusercontent.com/u/935867?v=4)](https://github.com/TomWright "TomWright (6 commits)")

### Embed Badge

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

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

###  Alternatives

[pestphp/pest

The elegant PHP Testing Framework.

11.6k72.2M19.4k](/packages/pestphp-pest)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M324](/packages/drupal-core-dev)

PHPackages © 2026

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