bittyphp/view-plates

A Plates template view for Bitty.

v1.0.0 2019-01-20 18:35 UTC

This package is auto-updated.

Last update: 2023-05-16 12:39:22 UTC


README

Build Status Codacy Badge PHPStan Enabled Mutation Score Total Downloads License

A Plates template view for Bitty.

Installation

It's best to install using Composer.

$ composer require bittyphp/view-plates

Setup

Basic Usage

<?php

require(dirname(__DIR__).'/vendor/autoload.php');

use Bitty\Application;
use Bitty\View\Plates;

$app = new Application();

$app->getContainer()->set('view', function () {
    return new Plates(dirname(__DIR__).'/templates/', $options);
});

$app->get('/', function () {
    return $this->get('view')->renderResponse('index', ['name' => 'Joe Schmoe']);
});

$app->run();

Options

<?php

use Bitty\View\Plates;

$plates = new Plates(
    dirname(__DIR__).'/templates/',
    [
        // Sets the extension you want to use.
        'extension' => 'php',
    ]
);

Multiple Template Paths

If you have templates split across multiple directories, you can pass in an array with the paths to load from. Each path must have a namespace set as the array key.

The first path in the array will be considered the default.

<?php

use Bitty\View\Plates;

$plates = new Plates(
    [
        'public' => 'templates/',
        'admin' => 'admin/templates/',
    ]
);

$plates->render('admin::foo');
// Loads admin/templates/foo.php

$plates->render('bar');
// Loads templates/bar.php

Advanced

If you need to do any advanced customization, you can access the Plates engine directly at any time.

<?php

use Bitty\View\Plates;
use League\Plates\Engine;

$plates = new Plates(...);

/** @var Engine */
$engine = $plates->getEngine();