PHP code example of nicmaxcarter / slim-plates
1. Go to this page and download the library: Download nicmaxcarter/slim-plates library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicmaxcarter / slim-plates example snippets
use League\Plates\Engine;
use NicmaxCarter\SlimPlates\PlatesView;
$engine = new Engine(__DIR__ . '/templates', 'phtml');
$platesView = new PlatesView($engine);
$platesView->registerUrlFor($app->getRouteCollector()->getRouteParser());
use NicmaxCarter\SlimPlates\AssetHelper;
use Psr\Container\ContainerInterface;
AssetHelper::class => function (ContainerInterface $container) {
$settings = $container->get('settings');
$rootPath = realpath(__DIR__ . '/..');
$baseUrl = '/assets/';
$cdn = $settings['assets'] ?? '';
if (($settings['debug'] ?? false) === false && is_string($cdn) && $cdn !== '') {
$baseUrl = rtrim($cdn, '/') . '/assets/';
}
$assetsDirectory = $rootPath . '/public/assets';
return new AssetHelper(
manifestPath: $assetsDirectory . '/manifest.json',
baseUrl: $baseUrl,
assetsDirectory: $assetsDirectory,
);
},
use NicmaxCarter\SlimPlates\AssetHelper;
use NicmaxCarter\SlimPlates\Bootstrap\PlatesBootstrap;
use NicmaxCarter\SlimPlates\PlatesView;
/** @var PlatesView $platesView */
$platesView = $container->get(PlatesView::class);
$assetHelper = $container->get(AssetHelper::class);
PlatesBootstrap::registerAsset($platesView->getEngine(), $assetHelper);
PlatesBootstrap::registerIconsSvg($platesView->getEngine(), $assetHelper);
new AssetHelper(
manifestPath: $rootPath . '/public/assets/manifest.json',
baseUrl: 'https://cdn.example.com/assets/',
queryVersion: null,
);
use NicmaxCarter\SlimPlates\Responses;
return Responses::withTriggers($response, [
'notifySuccess' => 'Saved',
'reload-table' => '',
]);
use NicmaxCarter\SlimPlates\Flash\FlashToastKeys;
use NicmaxCarter\SlimPlates\Responses;
return Responses::redirectWithToast(
$response,
'/dash',
'Welcome back',
FlashToastKeys::SUCCESS,
$flash,
);
$this->insert("bridge::partials/flash-toasts", ["flash" => $flash])
use NicmaxCarter\SlimPlates\Middleware\AbstractViewContextMiddleware;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Interfaces\RouteInterface;
final class ViewContextMiddleware extends AbstractViewContextMiddleware
{
protected function context(Request $request): array
{
$layoutData = ['uinfo' => [], 'darkmode' => ''];
$route = $request->getAttribute('__route__');
if ($route instanceof RouteInterface) {
$routeName = $route->getName();
if (is_string($routeName) && $routeName !== '') {
$layoutData['active'] = $routeName;
}
}
// … app-specific keys (uinfo, darkmode, flash, etc.)
return $layoutData;
}
}