PHPackages                             blat/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. blat/slim-plates

ActiveLibrary[Framework](/categories/framework)

blat/slim-plates
================

Slim Framework 4 view helper built on top of the Plates templating component

v0.1.1(3y ago)0229MITPHPPHP ^7.4 || ^8.0

Since Jul 31Pushed 3y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Slim Framework Plates View
==========================

[](#slim-framework-plates-view)

This is a Slim Framework view helper built on top of the Plates templating component. You can use this component to create and render templates in your Slim Framework application.

Install
-------

[](#install)

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

```
$ composer require blat/slim-plates
```

Requires Slim Framework 4, Plates 3 and PHP 7.4 or newer.

Usage
-----

[](#usage)

```
use DI\Container;
use Slim\Factory\AppFactory;
use Slim\Views\Plates;
use Slim\Views\PlatesExtension;

require __DIR__ . '/vendor/autoload.php';

// Create Container
$container = new Container();
AppFactory::setContainer($container);

// Set Plates View in Container
$container->set('view', function () {
    return new Plates(__DIR__ . '/../templates');
});

// Create App
$app = AppFactory::create();

// Add Plates Extension Middleware
$app->add(new PlatesExtension($app));

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

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

Custom template functions
-------------------------

[](#custom-template-functions)

`PlatesExtension` provides these functions to your Plates templates:

- `urlFor()` - returns the URL for a given route. e.g.: /hello/world
- `fullUrFor()` - returns the URL for a given route. e.g.:
- `isCurrentUrl()` - returns true is the provided route name and parameters are valid for the current path.
- `currentUrl()` - returns the current path, with or without the query string.
- `basePath()` - returns the base path.

You can use `urlFor` to generate complete URLs to any Slim application named route and use `isCurrentUrl` to determine if you need to mark a link as active as shown in this example Plates template:

```
