Slim 4 CSRF Protection?

Solution: use it without Middleware

Instead of using a separate middleware for CSRF Attack Protection, we should use it directly in our bootstrapper file like this

Now you can use these csrf fields in you template files like this
image

Ps: update this block as per your requirements or you can move these all to different file as well

Adding Twig v3 Globals for csrf fields will give you this error in Slim 4
Unable to add global “csrf” as the runtime or the extensions have already been initialized.
To fix these I implemented this answer.

Thanks & Regards
shindea890@gmail.com