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

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

rkr/view
========

More secure and easy to use templating system for PHP 8.2+

0.4.0(2mo ago)45211MITPHPPHP &gt;= 8.2

Since Sep 1Pushed 1y ago3 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (26)Used By (0)

php-view
========

[](#php-view)

[![SensioLabsInsight](https://camo.githubusercontent.com/884365a0ea4906615e14dda3e51eb2bb32a9d3c3c645ad0879fae580577cc4cc/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62613063643334642d666464352d343164342d393333662d6363636539313639336339632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/ba0cd34d-fdd5-41d4-933f-ccce91693c9c)[![Build Status](https://camo.githubusercontent.com/6ca6174b5e66736cfc02681b62cb6ef1fd4bf15515deb956770c71e8e4ece8f5/68747470733a2f2f7472617669732d63692e6f72672f726b72782f7068702d766965772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rkrx/php-view)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cda3c5c089f6626d27d72d57f13befe696932dd5cf054dc9ba3b79b42af4d389/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726b72782f7068702d766965772f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/rkrx/php-view/?branch=master)

More secure and easy to use templating system for php5.4+.

Design goals:

- Interface-driven and dependency-injection-friendly
- Secure by default, unsecure if needed
- Lightweight, easy to understand and stable
- No extra scripting language. Use PHP to write templates.

Jumpstart
---------

[](#jumpstart)

You will need this somewhere to convert a template-file into a string:

```
$factory = new FileViewFactory(__DIR__.'/path/to/my/template/folder');
$renderer = $factory->create('module');
$renderer->add('myVar', 1234);
$content = $renderer->render('action');
echo $content;
```

`FileViewFactory` implements an interface called `ViewFactory`. You can use this interface to Build your very own Factories that create different renderers and so on. This is especially useful, if you need a way to change the change the implementation some day. This is also useful it you use a Dependency Injection Container to wire your components together:

```
class MyCtrl {
	/** @var ViewFactory */
	private $viewFactory;

	/**
	 * @param ViewFactory $viewFactory
	 */
	public function __construct(ViewFactory $viewFactory) {
		$this->viewFactory = $viewFactory;
	}

	/**
	 * @return string
	 */
	public function someAction() {
		$content = $this->viewFactory->create('module')
		->add('myVar', 1234)
		->render('action');
		return $content;
	}
}
```

Use typehinting
---------------

[](#use-typehinting)

In PHP-Templates, you can use typehinting which is recognized by IDEs like PHPStorm, ZendStudio or PDT (and maybe others).

index.phtml

```
