2017 © Pedro Peláez
 

library view

Standalone templating system for PHP scripts.

image

phower/view

Standalone templating system for PHP scripts.

  • Sunday, April 9, 2017
  • by pedrobrazao
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Phower View

Standalone templating system for PHP scripts., (*1)

Requirements

Phower View requires:, (*2)

Instalation

Add Phower View to any PHP project using Composer:, (*3)

composer require phower/view

Usage

This package provides the essential tools for an application to output any kind of output response supported by an optional list of variables which are rendered inside templates., (*4)

Templates are plain PHP scripts which are rendered on a protected environment with all variables already available:, (*5)

<h1>Hello <?= $name ?>!</h1>

Assuming the template above is a file called my_template.php then we can use it to output a new set of variables:, (*6)

use Phower\View\TemplateView;

$view = new TemplateView();
$view->setTemplate('my_template.php');
$view->setVariables(['name'] => 'Pedro');

$view->render(); // outputs: 

Hello Pedro!

Templates inside templates

Many times we find useful to implement more than one layer of templating with high level ones outputing other templates., (*7)

This can be achived by capturing the child template into a variable of the parent template:, (*8)

use Phower\View\TemplateView;

$child = new TemplateView();
$child->setTemplate('child_template.php');

$parent = new TemplateView();
$parent->setTemplate('parent_template.php');
$parent->capture('child', $child);

$parent->render();

JSON views

Other times we may wish to output a set of variables not using a template but just as a JSON plain representation:, (*9)

use Phower\View\JsonView;

$view = new JsonView();
$view->setVariables(['name'] => 'Pedro');

$view->render(); // outputs: {"name":"Pedro"}

Note that JsonTemplate is fully compatible with PHP json_encode so that we can also set options and depth and use all the accepted values there on each instance of JsonTemplate., (*10)

Running Tests

Tests are available in a separated namespace and can run with PHPUnit in the command line:, (*11)

vendor/bin/phpunit

Coding Standards

Phower code is written under PSR-2 coding style standard. To enforce that CodeSniffer tools are also provided and can run as:, (*12)

vendor/bin/phpcs

Reporting Issues

In case you find issues with this code please open a ticket in Github Issues at https://github.com/phower/view/issues., (*13)

Contributors

Open Source is made of contribuition. If you want to contribute to Phower please follow these steps:, (*14)

  1. Fork latest version into your own repository.
  2. Write your changes or additions and commit them.
  3. Follow PSR-2 coding style standard.
  4. Make sure you have unit tests with full coverage to your changes.
  5. Go to Github Pull Requests at https://github.com/phower/view/pulls and create a new request.

Thank you!, (*15)

Changes and Versioning

All relevant changes on this code are logged in a separated log file., (*16)

Version numbers follow recommendations from Semantic Versioning., (*17)

License

Phower code is maintained under The MIT License., (*18)

The Versions

09/04 2017

dev-master

9999999-dev

Standalone templating system for PHP scripts.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Avatar Pedro Ferreira

09/04 2017

1.0.0

1.0.0.0

Standalone templating system for PHP scripts.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Avatar Pedro Ferreira