Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/projek-xyz/slim-plates
Render your Slim 3 application views using Plates template engine.
https://github.com/projek-xyz/slim-plates
plates-templates slim-framework
Last synced: 18 days ago
JSON representation
Render your Slim 3 application views using Plates template engine.
- Host: GitHub
- URL: https://github.com/projek-xyz/slim-plates
- Owner: projek-xyz
- License: mit
- Created: 2015-09-09T03:41:09.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-10-22T18:41:58.000Z (about 2 months ago)
- Last Synced: 2024-11-09T16:24:48.573Z (about 1 month ago)
- Topics: plates-templates, slim-framework
- Language: PHP
- Homepage: http://www.projek.xyz/slim-plates
- Size: 188 KB
- Stars: 27
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-slim - Slim Plates - Render your Slim application views using Plates template engine. (Templating)
README
[![Version](https://img.shields.io/packagist/v/projek-xyz/slim-plates?style=flat-square)](https://packagist.org/packages/projek-xyz/slim-plates)
[![Lisence](https://img.shields.io/github/license/projek-xyz/slim-plates?style=flat-square)](https://github.com/projek-xyz/slim-plates/blob/main/LICENSE)
[![Actions Status](https://img.shields.io/github/actions/workflow/status/projek-xyz/slim-plates/test.yml?branch=main&style=flat-square)](https://github.com/projek-xyz/slim-plates/actions)
[![Coveralls](https://img.shields.io/coveralls/projek-xyz/slim-plates/master.svg?style=flat-square&logo=coveralls)](https://coveralls.io/github/projek-xyz/slim-plates)
[![Code Climate](https://img.shields.io/codeclimate/coverage/projek-xyz/slim-plates.svg?style=flat-square&logo=code-climate)](https://codeclimate.com/github/projek-xyz/slim-plates/coverage)
[![Maintainability](https://img.shields.io/codeclimate/maintainability/projek-xyz/slim-plates?style=flat-square&logo=code-climate)](https://codeclimate.com/github/projek-xyz/slim-plates/maintainability)
[![SymfonyInsight Grade](https://img.shields.io/symfony/i/grade/69e58aaf-5d08-45f8-a9a7-8f246e031ec0?style=flat-square&logo=symfony)](https://insight.symfony.com/projects/69e58aaf-5d08-45f8-a9a7-8f246e031ec0)# Plates Template Integration for Slim micro framework 3
Render your Slim 3 application views using Plates template engine.
## Install
Via [Composer](https://getcomposer.org/)
```bash
$ composer require projek-xyz/slim-plates --prefer-dist
```Requires Slim micro framework 3 and PHP 5.5.0 or newer.
## Usage
```php
// 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
This component exposes some Slim functions to your Plates templates.
### `pathFor()`
You can use this function to generate complete URLs to any Slim application named route. Example:
```php
layout('base-template') ?>start('body') ?>
Hallo =$this->e($name)?>
=$this->pathFor('profile', ['name'=> $name])?>
stop() ?>
```### `baseUrl($permalink = '')`
Retrieve the base url of your Slim application. Example:
```php
Some Link
```Or you can pass a permalink
```php
Some Other Link
```### `basePath()`
Retrieve the base url of your Slim application. Example:
```php
```
### `uriFull()`
Retrieve full request URI.
### `uriScheme()`
Retrieve the [scheme](https://tools.ietf.org/html/rfc3986#section-3.1) component of the URI.
### `uriHost()`
Retrieve the [host](http://tools.ietf.org/html/rfc3986#section-3.2.2) component of the URI
### `uriPort()`
Retrieve the [port](https://tools.ietf.org/html/rfc3986#section-3.2.3) component of the URI.
### `uriPath()`
Retrieve the [path](https://tools.ietf.org/html/rfc3986#section-3.3) component of the URI.
### `uriQuery()`
Retrieve the [query string](https://tools.ietf.org/html/rfc3986#section-3.4) component of the URI.
### `uriFragment()`
Retrieve the [fragment](https://tools.ietf.org/html/rfc3986#section-3.5) component of the URI.
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CONDUCT](.github/CONDUCT.md) for details.
## License
This library is open-sourced software licensed under [MIT license](LICENSE.md).