2017 © Pedro Peláez
 

library sliphp

Atomic view and layout engine for PHP 5.4 and above

image

sbstjn/sliphp

Atomic view and layout engine for PHP 5.4 and above

  • Saturday, October 17, 2015
  • by sbstjn
  • Repository
  • 0 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

, (*1)

Circle CI Travis CI Scrutinizer
Scrutinizer Code Quality Scrutinizer Code Coverage
Packagist MIT License , (*2)

Atomic view and layout engine for PHP 5.4 and above., (*3)

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., (*4)

Installation

composer require sbstjn/sliphp

Basics

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

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

The folder structure inside your SLIPHP_VIEWS path should look something like this:, (*6)

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

Views

It's that simple to render a view from your SLIPHP_VIEWS folder:, (*7)

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

Your index.php could look like this:, (*8)

<strong>Hi!</strong>

Layouts

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

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

die($layout);

Your layouts/default.ph file could look like this:, (*10)

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>SliPHP</title>
    <meta charset="utf-8" />
  </head>
  <body><?=$view->body()?></body>
</html>

As you might guess, the content of your view gehts inserted inside the body tag. Woho, Magic …, (*11)

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:, (*12)

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>SliPHP Example</title>
    <?=$view->block('header')?>
  </head>
  <body><?=$view->body()?></body>
</html>

Your blocks/header.php could look like this:, (*13)

<meta charset="utf-8" />

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

<meta charset="utf-8" />

=$view->block('styles')?>
=$view->block('script')?>

Apply

If you want to apply a function or a list of functions to a data object, you can use the $view->apply function to modify your data:, (*15)

<strong><?=$view->apply('KATZE', 'ucfirst|strtolower')?><?=$view->apply('KATZE', 'strtolower|ucfirst')?></strong>

Will be rendered into:, (*16)

<strong>katzeKatze</strong>

Helper

There is built in support for custom helper functions in SliPHP, just define your helpers like this:, (*17)

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

$view->helper('strong', function($value) {
    return '<strong>' . $value . '</strong>';
});

And call them inside your views with:, (*18)

<?=$view->strong('hi')?>

You can for example use this to easily include your stylesheets:, (*19)

$view->helper('css', function($file) {
    return '<link rel="stylesheet" href="' . $file . '" type="text/css" charset="utf-8" />';
});

Locals

Of course you can pass data to your views, SliPHP calls them Locals …, (*20)

$view = new SliPHP\View('index');
$view->set('foo', 'value');

You can access all your data using the $data variable inside your layouts, views and of course blocks:, (*21)

<?=$data->foo?>

It's also possible to share locals between your layout and your views:, (*22)

$layout = new SliPHP\Layout('default');
$layout->set('foo', 'value');
$layout->body('index');

Inside your index view you can now easily access to layout's locals:, (*23)

<?=$data->foo?>

Change log

Please see CHANGELOG for more information what has changed recently., (*24)

Testing

bash $ composer test, (*25)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*26)

Security

If you discover any security related issues, please email mail@sbstjn.com instead of using the issue tracker., (*27)

Credits

License

The MIT License (MIT). Please see License File for more information., (*28)

The Versions

17/10 2015

dev-master

9999999-dev https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

17/10 2015

0.2.1

0.2.1.0 https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

17/10 2015

dev-update-readme

dev-update-readme https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

17/10 2015

dev-new-locals-handling

dev-new-locals-handling https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

13/10 2015

0.2.0

0.2.0.0 https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

13/10 2015

dev-cleanup

dev-cleanup https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

08/10 2015

0.1.1

0.1.1.0 https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar sbstjn

framework template engine view layout render

06/10 2015

0.1.0

0.1.0.0 https://github.com/sbstjn/SliPHP

Atomic view and layout engine for PHP 5.4 and above

  Sources   Download

MIT

The Requires

  • php >= 5.4.4

 

by Avatar sbstjn

framework template engine view layout render