PHPackages                             kiryi/viewyi - 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. kiryi/viewyi

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

kiryi/viewyi
============

Native PHP view engine for web applications.

1.1.2(5y ago)0441GPL-3.0-or-laterPHPPHP ^7.4

Since Apr 6Pushed 5y agoCompare

[ Source](https://github.com/KiryiMONZTA/viewyi)[ Packagist](https://packagist.org/packages/kiryi/viewyi)[ Docs](https://kiryi.net/)[ RSS](/packages/kiryi-viewyi/feed)WikiDiscussions master Synced 6d ago

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

Kiryi's VIEWYI
==============

[](#kiryis-viewyi)

A native PHP view engine for web applications.

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

[](#installation)

```
composer require kiryi/viewyi
```

Usage
-----

[](#usage)

First initialize the engine in one of three possible ways. See [Initialization](#initialization) for more information. Then use the provided functions as described below. Also build your templates as described in the section [Templating](#templating).

Constructor Definition
----------------------

[](#constructor-definition)

```
__construct($config)
```

### Parameters

[](#parameters)

**config**
Optional configuration array or filepath to custom configuration INI file. If nothing is provided, default (*config/viewyi.ini*) is used ([more information](#initialization)).

Method Definition *assign*
--------------------------

[](#method-definition-assign)

```
assign(string $key, $value): void
```

Assigns a variable to the view's data object.

### Parameters

[](#parameters-1)

**key**
The variable's key.

**value**
The variable's value. Can be string, any number, array, bool or null.

Method Definition *render*
--------------------------

[](#method-definition-render)

```
render(string $template): string
```

Renders the current view (HTML page). Have to be called before `display`.

### Parameters

[](#parameters-2)

**template**
The template name to use as render base.

### Return Values

[](#return-values)

Returns the fully rendered view.

Method Definition *reset*
-------------------------

[](#method-definition-reset)

```
reset(): string
```

Resets the view's data object and view object. This helps dealing with large pages and especially in case of nested templates.

### Return Values

[](#return-values-1)

Returns the current fully rendered view.

Method Definition *display*
---------------------------

[](#method-definition-display)

```
display(string $headTemplate, string $title): void
```

Finally displays the whole HTML page. It is necessary to call `render` at least once before. The rendered view is always embeded to the page's HTML body element. `display` can only be called once.

### Parameters

[](#parameters-3)

**headTemplate**
The template name to embed into the HTML page's head element.

**title**
The title of the current page set to the HTML page's title element.

Initialization
--------------

[](#initialization)

You have to provide the engine at least three mandatory parameters as well as an optional fourth.

**baseUrl**
The base URL of your web application.

**imagePath**
The image directory path relative to your base URL.

**templateDirectory**
The template directory path relative to your project's root directory.

**templateFileExtension (optional)**
Optional file extension of your template files, if you want to use something else than the default `.php`.

The parameters can be provided by using the standard configuration file `{PROJECTSROOTDIRECTORY}/config/viewyi.ini` with the following contents:

```
[viewyi]
baseUrl = {YOURBASEURL}
imagePath = {YOURIMAGEDIRECTORYPATH}
templateDirectory = {YOURTEMPLATEDIRECTORYPATH}
templateFileExtension = {YOURFILEEXTENSION}
```

Or by passing another INI file path to the engines's constructor with the same contents. The path has to be relative to your project's root directory:

```
$viewyi = new \Kiryi\Viewyi\Engine('{YOURCUSTOMFILEPATH}');
```

Or by passing an array with the three to four parameters to the constructor:

```
$viewyi = new \Kiryi\Viewyi\Engine([
    'baseUrl' => '{YOURBASEURL}',
    'imagePath' => '{YOURIMAGEDIRECTORYPATH}',
    'templateDirectory' => '{YOURTEMPLATEDIRECTORYPATH}',
    'templateFileExtension' => '{YOURFILEEXTENSION}',
]);
```

Templating
----------

[](#templating)

- Use native PHP templates.
- Therefore you may use any PHP alternative syntax control structure.
- Print any data you have assigned by writing ``.
- Build links with your base URL by writing `
