I got it working. I’m not 100% sure I understand it properly, but I believe the issue was passing the app/container to the different steps and getting values added to them correctly.In case it comes up for others here’s the final layout:
settings.php
<?php
//Uses
use Psr\Container\ContainerInterface;
//Returns the settings from the container
return function (ContainerInterface $container) {
//Settings
$container->set ('settings', function () {
return [
'displayErrorDetails' => true,
'logErrorDetails' => true,
'logErrors' => true,
'views' => [
'path' => __DIR__.'/../resources/views',
'settings' => ['cache' => false,
'auto_reload' => true],
],
];
});
};
views.php
<?php
//Uses
use Slim\App;
use Slim\Views\Twig;
//Returns the call based on the route. This is where the new tools get listed
return function (App $app) {
$container = $app->getContainer ();
$container->set ('view', function ($container) {
$settings = $container->get ('settings')['views'];
return Twig::create ($settings['path'], $settings['settings']);
});
};
middleware.php
<?php
//Uses
use Slim\App;
use Slim\Views\TwigMiddleware;
//Runs the middleware
return function (App $app) {
//Pull values from container
$setting = $app->getContainer ()->get ('settings');
//Twig
$app->add (TwigMiddleware::create ($app, $app->getContainer ()->get ('view')));
//Error handling
$app->addErrorMiddleware (
$setting['displayErrorDetails'],
$setting['logErrors'],
$setting['logErrorDetails']
);
};
routes.php
<?php
//Uses
use Slim\App;
use Slim\Views\Twig;
use App\Controllers\ToolController;
use App\Controllers\TwigController;
//Returns the call based on the route. This is where the new tools get listed
return function (App $app) {
//Testing twig
$app->get ('/twig[/{name}]', [TwigController::class, 'twigTest']);
//Undefined route
$app->get ('/{tool}[/{step}]', [ToolController::class, 'selectTool']);
};
TwigController.php
<?php
//Uses and namespaces
namespace App\Controllers;
use Slim\Views\Twig;
//Define the class
class TwigController {
public function twigTest ($request, $response, $name = NULL) {
$view = Twig::fromRequest ($request);
return $view->render ($response, 'twigTest.php', [
'name' => $name,
]);
}
}
twigTest.php
<div style="padding: 10px">
<p>
Auth home page for {{ name }}
</p>
</div>