I parsed out the two different view outputs to different controllers, jsut in case there was some logic contradiction I didn’t know about.
Updated routes.php
<?php
//Uses
use Slim\App;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
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']);
};
separated TwigController.php
<?php
//Uses and namespaces
namespace App\Controllers;
use Slim\Views\Twig;
//Define the class
class TwigController {
protected $view;
public function __construct (Twig $views) {
return $this->view = $views;
}
public function twigTest ($request, $response, $name){
return $this->view->render ($response, 'auth\home.twig', ['name' => $name]);
}
}
Entering anything in my URL other than …/twig/foo shows the expected text output
Entering a twig URL gets the same error. I tried loading Twig directly from the request variable as I had seen some tutorials do and so the code then looked like this:
<?php
//Uses and namespaces
namespace App\Controllers;
use Slim\Views\Twig;
//Define the class
class TwigController {
protected $view;
public function __construct () {
}
public function twigTest ($request, $response, $name){
return Twig::fromRequest ($request)->render ($response, 'auth\home.twig', ['name' => $name]);
}
}
and that changed my error message to
Twig could not be found in the server request attributes using the key "view".
Which this post: Adding Twig to Slim4 Skeleton
suggests is an issue of when I’m adding the TwigMiddleware, but given how php-di/slim-bridge changed the middleware implementation I have no idea how I can restructure it.