Errore running example from documentation on fresh installation
// Render Twig template in route
$app->get('/hello/{name}', function ($request, $response, $args) {
return $this->view->render($response, 'profile.html', [
'name' => $args['name']
]);
})->setName('profile');
</code>
error :
Fatal error: Uncaught Error: Using $this when not in object context
while this works:
<code>
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello world!");
return $response;
});
</code<
odan
2
I could not find your example in the documentation.
Fatal error: Uncaught Error: Using $this when not in object context
Your example works only within a class / object, but not within a callback function.
Have you tried this? Templates - Slim Framework
1 Like
https://www.slimframework.com/docs/v3/features/templates.html#the-slimtwig-view-component
probabilly I made error using example for v3 but Iām using v4
how can I render template in v4 ?
odan
4
how can I render template in v4 ?
You can find the link in my previous answer.
1 Like