dlundgren/phrender

Simple PHP Renderer

0.1.3 2018-07-01 17:08 UTC

This package is auto-updated.

Last update: 2024-11-18 21:36:14 UTC


README

Travis CI Code Climate

Phrender is a simplistic PHP renderer that provides a no frills rendering engine.

PSR-1 and PSR-4 compliant.

This uses the Output Interop specification.

Contexts

The following contexts are provided for use:

  • Collection Any number of the following
  • Any Matches any template
  • Contains uses stripos to match the template
  • Match Uses a regex to match the template
  • Only Will match only the specified template

Installation

Phrender can be installed using composer

composer require dlundgren/phrender

Basic Usage

<?php

$factory = new Phrender\Template\Factory(['/path/to/views']);
$engine = new Phrender\Engine($factory, new Phrender\Context\Collection());

// index.php: <?= $this->var ?>

// output = "something"
$output = $engine->render('index', ['var' => 'something']); 

// Alternate
// output = ""
$ctxt   = new Phrender\Context\Contains('something', ['var' => 'display']);
$output = $engine->render('index', $ctxt); 

Different extension

You may use an alternate extension for the templates with the Template Factory constructor second argument.

$factory = new Phrender\Template\Factory(['/path/to/views'], 'phtml');
$engine = new Phrender\Engine($factory, new Phrender\Context\Collection());

// index.phtml: <?= $this->var ?>

// output = "something"
$output = $engine->render('index', ['var' => 'something']);