2017 © Pedro Peláez
 

library surface

A template rendering system.

image

netherphp/surface

A template rendering system.

  • Thursday, December 21, 2017
  • by bobmajdakjr
  • Repository
  • 0 Watchers
  • 0 Stars
  • 216 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 6 % Grown

The README.md

Nether Surface

nether.io Build Status Packagist Packagist, (*1)

Installing

Require this package in your composer.json. This will also include Object, Stash, and Option., (*2)

$ composer require netherphp/surface

Creating a Surface Theme

  • Project Root: /opt/website/www
  • Surface Theme Dir: /opt/website/www/themes
  • Default Theme: /opt/website/www/themes/default
  • Main Template: /opt/website/www/themes/default/design.phtml
  • Surface Area Dir: /opt/website/www/themes/default/area/

Your design.phtml is what defines the entire theme. Once you make that, it is pretty open ended what you do next. That file will basically be your html, head, and body tags. Take for example this super simple template., (*3)

<html>
<head>
    <title><?php $this->Show('page-title') ?></title>
</head>
<body>
<?php $this->ShowArea('header') ?>

<div>
    <?php $this->Show('stdout') ?>
</div>

<?php $this->ShowArea('footer') ?>
</body>
</html>

This example will show the page title which could have been defined by the app at any time, as well as include the files header.phtml and footer.phtml which it will attempt to find in the /opt/website/www/themes/default/area directory. In the main area of the page it dumped the main application output., (*4)

Note: The $this will only work if you are on PHP 5.6+ or newer. In order to access Surface on older versions of PHP you can use the $surface variable instead, which is created in the template scopes for you., (*5)

<html>
<head>
    <title><?php $surface->Show('page-title') ?></title>
...

Starting Surface

Surface uses Nether Option to handle base configuration. As a bare minimum it needs to know two things about your application: the file path to your web root, and the URI path to the web root., (*6)

Nether\Option::Set([
    'nether-web-root' => '/opt/website/www',
    'nether-web-path' => '/'
]);

new Nether\Surface;

This tells surface to look in /opt/website/www for the themes directory it will work with, and that the browser will be able to find the themes on the web root. This translates into /opt/website/www/themes = /themes/., (*7)

Afterwards it created a new instance of the Nether Surface engine and hillariously forgot about it. But not really. By default Surface will stash itself. So this code above you can drop that into the configuration that happens before your app even begins and surface will be ready and waiting., (*8)

If you do nothing else, whenever your application ends Surface will automatically throw itself together and chuck out the page at the very last moment., (*9)

Using Surface

At any point in your application you can access that Surface instance through the Nether Stash., (*10)

Nether\Stash::Get('surface')
->Set('name',$user->Name)
->Set('email',$user->Email)
->ShowArea('forms/user-change-info');

This will make the values of name and email available to the theme engine and then print out the {$theme}/area/forms/user-change-info.phtml surface area., (*11)

At any point inside the template (.phtml) files you can access surface via the $surface variable. If you are on PHP 5.6+ you can use $this instead., (*12)

<form>
    <div>
        Your Name:
        <input type="text" name="name" value="<?php $this->Show('name') ?>" />
    </div>
    <div>
        Your Email:
        <input type="text" name="email" value="<?php $this->Show('email') ?>" />
    </div>
</form>

The show method will automatically htmlentities() the data for you. If you need the data straight up use echo $this->Get('key') instead., (*13)

The Versions

21/12 2017

dev-master

9999999-dev

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

21/12 2017

v3.0.2

3.0.2.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

20/12 2017

v3.0.1

3.0.1.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

20/08 2017

v3.0.0

3.0.0.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

11/04 2017

v2.2.0

2.2.0.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

30/05 2016

v2.1.2

2.1.2.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

30/05 2016

v2.1.1

2.1.1.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

04/04 2016

v2.0.1

2.0.1.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

26/02 2016

v2.0.0

2.0.0.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

04/09 2015

v1.1.1

1.1.1.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

30/07 2015

v1.1.0

1.1.0.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

30/07 2015

dev-refresh

dev-refresh

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

27/07 2015

v1.0.1

1.0.1.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php

27/05 2015

v1.0.0

1.0.0.0

A template rendering system.

  Sources   Download

BSD-3-Clause

The Requires

 

template php