PHPackages                             sbstjn/sliphp - 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. [Framework](/categories/framework)
4. /
5. sbstjn/sliphp

ActiveLibrary[Framework](/categories/framework)

sbstjn/sliphp
=============

Atomic view and layout engine for PHP 5.4 and above

0.2.1(10y ago)1231MITPHPPHP &gt;=5.4.0

Since Oct 6Pushed 10y agoCompare

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

READMEChangelog (4)Dependencies (2)Versions (8)Used By (0)

 [![](https://camo.githubusercontent.com/e9d5f959d2fdf188c8895b59ac13365d868227ac3c6ad3b5dbcec6574e0ab674/68747470733a2f2f63646e2e7261776769742e636f6d2f736273746a6e2f536c695048502f6d61737465722f6c6f676f2e737667)](https://camo.githubusercontent.com/e9d5f959d2fdf188c8895b59ac13365d868227ac3c6ad3b5dbcec6574e0ab674/68747470733a2f2f63646e2e7261776769742e636f6d2f736273746a6e2f536c695048502f6d61737465722f6c6f676f2e737667)

 [![Circle CI](https://camo.githubusercontent.com/d88790efaca9e0e76b127924174bb51da10b9dbd8dbd752e88f7199710dca708/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f70726f6a6563742f736273746a6e2f536c695048502f6d61737465722e737667)](https://circleci.com/gh/sbstjn/SliPHP/) [![Travis CI](https://camo.githubusercontent.com/617c9fa89428435620a189f9da578beeaa7131014754e1d598be5743652a74ad/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f736273746a6e2f536c695048502e737667)](https://travis-ci.org/sbstjn/SliPHP) [![Scrutinizer](https://camo.githubusercontent.com/d8d6df78f114b2a6ac2db9b906a49cecb61d8afba3496489d61a3865d58773e8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f736273746a6e2f536c695048502e737667)](https://scrutinizer-ci.com/g/sbstjn/SliPHP/)
 [![Scrutinizer Code Quality](https://camo.githubusercontent.com/f57a5fb2a8e22b35ad14fac30b0480389406141cea7dcc00b6765a6102dd9270/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f736273746a6e2f536c695048502e737667)](https://scrutinizer-ci.com/g/sbstjn/SliPHP) [![Scrutinizer Code Coverage](https://camo.githubusercontent.com/3a6f6267da7a0944b52befc341aea9c5923e389e0fa4d197c646203defd6c45b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f736273746a6e2f536c695048502e737667)](https://scrutinizer-ci.com/g/sbstjn/SliPHP/)
 [![Packagist](https://camo.githubusercontent.com/138b237e0fd8ae4af284a896dc462d79c98dc533db8446f5e51e99547ff1bb3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736273746a6e2f536c695048502e737667)](https://packagist.org/packages/sbstjn/sliphp) [![MIT License](https://camo.githubusercontent.com/147c5d6cc3cb505433dd69b0f698aa6b895a8c73c29b69d6e81d9a804e0e215a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736273746a6e2f536c695048502e737667)](https://github.com/sbstjn/SliPHP/blob/master/LICENSE.md)

**Atomic view and layout engine for PHP 5.4 and above.**

Usage
-----

[](#usage)

To use **SliPHP** please configure the global constant `SLIPHP_VIEWS` and set it to the directory where your *views*, *layouts* and *blocks* are located.

### Installation

[](#installation)

```
composer require sbstjn/sliphp
```

### Basics

[](#basics)

As mentioned above, just configure the needed constant and you are good to go …

```
define ('SLIPHP_VIEWS', '/var/www/views/');
```

The folder structure inside your `SLIPHP_VIEWS` path should look something like this:

```
/var/www/views/index.php (View)
/var/www/views/layouts/default.php (Layout)
/var/www/views/blocks/header.php (Block)

```

### Views

[](#views)

It's that simple to render a view from your `SLIPHP_VIEWS` folder:

```
$view = new SliPHP\View('index');
die($view);
```

Your `index.php` could look like this:

```
Hi!
```

### Layouts

[](#layouts)

Of course you want to have a separate file for your layout, which will be wrapped around your `index` view:

```
$layout = new SliPHP\Layout('default');
$layout->body(new SliPHP\View('index'));

die($layout);
```

Your `layouts/default.ph` file could look like this:

```
DOCTYPE html>

    SliPHP

```

As you might guess, the content of your view gehts inserted inside the `body` tag. Woho, Magic …

### Blocks

[](#blocks)

For sure **SliPHP** supports loading single files and have them rendered into your views and layouts. We call them *blocks*, just use the `->block()` method for loading them:

```
DOCTYPE html>

    SliPHP Example

```

Your `blocks/header.php` could look like this:

```

```

Blocks can load other blocks as well, so feel free to move your styles and script to separate files for example:

```
