PHPackages                             projek-xyz/slim-plates - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. projek-xyz/slim-plates

ActiveLibrary[Framework](/categories/framework)

projek-xyz/slim-plates
======================

Render your Slim 3 application views using Plates template engine.

v0.2.2(9y ago)2678.2k↓42.7%2[5 PRs](https://github.com/projek-xyz/slim-plates/pulls)3MITPHPPHP &gt;=5.5.0CI passing

Since Sep 9Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/projek-xyz/slim-plates)[ Packagist](https://packagist.org/packages/projek-xyz/slim-plates)[ Docs](http://www.projek.xyz/slim-plates)[ RSS](/packages/projek-xyz-slim-plates/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (16)Used By (3)

[![Version](https://camo.githubusercontent.com/47903e422193f398cd5ef70da2c065c5dc4306d1f2e89c7025021a717a847ec9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70726f6a656b2d78797a2f736c696d2d706c617465733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/projek-xyz/slim-plates)[![Lisence](https://camo.githubusercontent.com/740a9849918960f671ece91926ca662bd5e35ccf5d38ac5c4472f089ee618a0e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70726f6a656b2d78797a2f736c696d2d706c617465733f7374796c653d666c61742d737175617265)](https://github.com/projek-xyz/slim-plates/blob/main/LICENSE)[![Actions Status](https://camo.githubusercontent.com/0327c28e05db75eec5228f6233ff8835cd222cfacea04107c1fe36abb52945e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70726f6a656b2d78797a2f736c696d2d706c617465732f746573742e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/projek-xyz/slim-plates/actions)[![Coveralls](https://camo.githubusercontent.com/383256a04c503bf9c40492ddedde5bdaf447dd282151725edfe6fd72e4e220e4/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f70726f6a656b2d78797a2f736c696d2d706c617465732f6d61737465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f766572616c6c73)](https://coveralls.io/github/projek-xyz/slim-plates)[![Code Climate](https://camo.githubusercontent.com/5a20442793a1ba57bb5d7d721b04a6c44ac6e15a5b3fd961096163072663299e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f70726f6a656b2d78797a2f736c696d2d706c617465732e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f64652d636c696d617465)](https://codeclimate.com/github/projek-xyz/slim-plates/coverage)[![Maintainability](https://camo.githubusercontent.com/e232dd5a03c62b148e074feb974340098d8d39ee2df7365d10d2c7bece261485/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f70726f6a656b2d78797a2f736c696d2d706c617465733f7374796c653d666c61742d737175617265266c6f676f3d636f64652d636c696d617465)](https://codeclimate.com/github/projek-xyz/slim-plates/maintainability)[![SymfonyInsight Grade](https://camo.githubusercontent.com/c6ba0cdbd3bf70846d8d9a8f9b6a4b82a3e684ac47e14461f84218a82c01ebcb/68747470733a2f2f696d672e736869656c64732e696f2f73796d666f6e792f692f67726164652f36396535386161662d356430382d343566382d613961372d3866323436653033316563303f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79)](https://insight.symfony.com/projects/69e58aaf-5d08-45f8-a9a7-8f246e031ec0)

Plates Template Integration for Slim micro framework 3
======================================================

[](#plates-template-integration-for-slim-micro-framework-3)

Render your Slim 3 application views using Plates template engine.

Install
-------

[](#install)

Via [Composer](https://getcomposer.org/)

```
$ composer require projek-xyz/slim-plates --prefer-dist
```

Requires Slim micro framework 3 and PHP 5.5.0 or newer.

Usage
-----

[](#usage)

```
// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Plates View helper:
// Option 1, using PlatesProvider
$container->register(new \Projek\Slim\PlatesProvider);

// Option 2, using Closure
$container['view'] = function ($c) {
    $view = new \Projek\Slim\Plates([
        // Path to view directory (default: null)
        'directory' => 'path/to/views',
        // Path to asset directory (default: null)
        'assetPath' => 'path/to/static/assets',
        // Template extension (default: 'php')
        'fileExtension' => 'tpl',
        // Template extension (default: false) see: http://platesphp.com/extensions/asset/
        'timestampInFilename' => false,
    ]);

    // Set \Psr\Http\Message\ResponseInterface object
    // Or you can optionaly pass `$c->get('response')` in `__construct` second parameter
    $view->setResponse($c->get('response'));

    // Instantiate and add Slim specific extension
    $view->loadExtension(new Projek\Slim\PlatesExtension(
        $c->get('router'),
        $c->get('request')->getUri()
    ));

    return $view;
};

// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render('profile', [
        'name' => $args['name']
    ]);
})->setName('profile');

// Run app
$app->run();
```

**NOTE**:

- If you are using *option 1* please make sure you already have `$container['settings']['view']` in your configuration file.
- `Plates::setResponse()` is required to use `Plates::render()` otherwise `\LogicException` will thrown.

Custom functions
----------------

[](#custom-functions)

This component exposes some Slim functions to your Plates templates.

### `pathFor()`

[](#pathfor)

You can use this function to generate complete URLs to any Slim application named route. Example:

```
