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

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

popphp/pop-view
===============

Pop View Component for Pop PHP Framework

4.0.4(6mo ago)48.5k↓50%5BSD-3-ClausePHPPHP &gt;=8.3.0CI passing

Since Jul 16Pushed 6mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (30)Used By (5)

pop-view
========

[](#pop-view)

[![Build Status](https://github.com/popphp/pop-view/workflows/phpunit/badge.svg)](https://github.com/popphp/pop-view/actions)[![Coverage Status](https://camo.githubusercontent.com/e1667de97018d7a7856aa192d719b681b99ad24fae5503fa7ba978e9980c5cd8/687474703a2f2f63632e706f707068702e6f72672f636f7665726167652e7068703f636f6d703d706f702d76696577)](http://cc.popphp.org/pop-view/)

[![Join the chat at https://discord.gg/TZjgT74U7E](https://camo.githubusercontent.com/acad7b0eeb78b78d08ffd2b85681ab243436388b5f86f8bcb956a69246e53739/68747470733a2f2f6d656469612e706f707068702e6f72672f696d672f646973636f72642e737667)](https://discord.gg/TZjgT74U7E)

- [Overview](#overview)
- [Install](#install)
- [Quickstart](#quickstart)
- [File Template](#file-template)
- [Stream Template](#stream-template)
    - [Includes](#includes)
    - [Inheritance](#inheritance)
    - [Iteration](#iteration)
    - [Conditionals](#conditionals)

Overview
--------

[](#overview)

`pop-view` is the view template component that can be used as the "V" in an MVC stack or independently as well. It supports using both PHP-file based templates and stream templates. Within the stream templates, there is basic support for logic and iteration for dynamic control over the view template.

`pop-view` is a component of the [Pop PHP Framework](https://www.popphp.org/).

[Top](#pop-view)

Install
-------

[](#install)

Install `pop-view` using Composer.

```
composer require popphp/pop-view

```

Or, require it in your composer.json file

```
"require": {
    "popphp/pop-view" : "^4.0.4"
}

```

[Top](#pop-view)

Quickstart
----------

[](#quickstart)

Consider a `phtml` template file like this:

```

```

You can set up a view object and populate data like this:

```
use Pop\View\View;
use Pop\View\Template\File;

$view        = new View(new File('hello.phtml'));
$view->title = 'Hello World!';

echo $view;
```

which will produce:

```

    Hello World!

```

[Top](#pop-view)

File Template
-------------

[](#file-template)

A file template simply uses PHP variables to deliver the data and content to template to be rendered. With a file template, you have full access to the PHP environment to write any additional code or helper scripts. However, in using this, you must make sure to adhere to the best practices and standards regarding the security of the application.

##### hello.phtml

[](#hellophtml)

```
DOCTYPE html>

```

You can set up the view object like this:

```
use Pop\View\View;
use Pop\View\Template\File;

$view = new View(new File('hello.phtml'));
$view->title   = 'Hello World!';
$view->content = 'This is a test!';

echo $view;
```

[Top](#pop-view)

Stream Template
---------------

[](#stream-template)

A stream template uses a formatted string placeholder to deliver the data and content to template to be rendered:

##### hello.html

[](#hellohtml)

```
>

    [{title}]

    [{title}]
    [{content}]

```

You can set up the view object in a similar way and it will render the exact same as the file template example.

```
use Pop\View\View;
use Pop\View\Template\Stream;

$view = new View(new Stream('hello.html'));
$view->title   = 'Hello World!';
$view->content = 'This is a test!';

echo $view;
```

[Top](#pop-view)

### Includes

[](#includes)

Stream templates support includes to allow you to include other templates within them.

##### header.html

[](#headerhtml)

```

>

    [{title}]

    This is the header
```

##### footer.html

[](#footerhtml)

```

    This is the footer

```

##### index.html

[](#indexhtml)

```

{{@include header.html}}
    [{title}]
    [{content}]
{{@include footer.html}}
```

You can set up the view object like before:

```
use Pop\View\View;
use Pop\View\Template\Stream;

$view = new View(new Stream('index.html'));
$view->title   = 'Hello World!';
$view->content = 'This is a test!';

echo $view;
```

[Top](#pop-view)

### Inheritance

[](#inheritance)

Stream templates support inheritance to allow you to extend other templates.

##### parent.html

[](#parenthtml)

```

>

{{header}}
    [{title}]

{{/header}}

    [{title}]
    [{content}]

```

##### child.html

[](#childhtml)

```

{{@extends parent.html}}

{{header}}
{{parent}}

        body { margin: 0; padding: 0; color: #bbb;}

{{/header}}
```

You can set up the view object like before:

```
use Pop\View\View;
use Pop\View\Template\Stream;

$view = new View(new Stream('child.html'));
$view->title   = 'Hello World!';
$view->content = 'This is a test!';

echo $view;
```

[Top](#pop-view)

### Iteration

[](#iteration)

Iteration is possible in stream templates when working with arrays and array-like objects.

```

>

    [{title}]

[{items}]
    [{key}]: [{value}]
[{/items}]

```

```
use Pop\View\View;
use Pop\View\Template\Stream;

$data = [
    'items' => [
        'hello' => 'world',
        'foo'   => 'bar',
        'baz'   => 123
    ]
];

$view = new View(new Stream('index.html'), $data);

echo $view;
```

[Top](#pop-view)

### Conditionals

[](#conditionals)

Conditional logic is possible within a stream template as well.

```

>

    [{title}]

[{if(foo)}]
    The variable 'foo' is set to [{foo}].
[{else}]
    The variable 'foo' is not set.
[{/if}]

```

```
use Pop\View\View;
use Pop\View\Template\Stream;

$data = ['foo' => 'bar'];

$view = new View(new Stream('index.html'), $data);

echo $view;
```

[Top](#pop-view)

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance72

Regular maintenance activity

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

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

Recently: every ~181 days

Total

25

Last Release

186d ago

Major Versions

2.1.1 → 3.0.02017-02-22

v2.x-dev → 3.0.22018-01-29

3.3.1 → 4.0.02023-11-09

PHP version history (8 changes)2.0.0PHP &gt;=5.4.0

3.0.0PHP &gt;=5.6.0

3.1.0PHP &gt;=7.1.0

3.3.0PHP &gt;=7.3.0

3.3.1PHP &gt;=7.4.0

4.0.0PHP &gt;=8.1.0

4.0.2PHP &gt;=8.2.0

4.0.4PHP &gt;=8.3.0

### Community

Maintainers

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

---

Top Contributors

[![nicksagona](https://avatars.githubusercontent.com/u/898670?v=4)](https://github.com/nicksagona "nicksagona (79 commits)")

---

Tags

phptemplateviewpoppop phpview template

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[eftec/bladeonehtml

The standalone version Blade Template Engine from Laravel in a single php file

1018.1k5](/packages/eftec-bladeonehtml)

PHPackages © 2026

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