0

for a really specific project I have to use PHP files as template in Symfony, so I render them on my controller, but when I go on the right path in my browser, the PHP isn't interpreted then display code like html.

I've know that on older version Symfony it was easy to enable PHP template, but now I didn't find how with Symfony 6.

Does someone know how to do that ?

Example :

My index.php path : /templates/gfservphp/index.php

#[Route('/index', name: 'app_index_gf')]
public function indexgf(): Response
{
    return $this->render('gfservphp/index.php', [
        'controller_name' => 'MainController',
    ]);
}
Noctissei
  • 1
  • 1
  • Hey Noctissei, does [this answer](https://stackoverflow.com/a/22448438/3808452) help you? It describes a function to render PHP templates and save the output as a string. All you have to do is to return that from your controller, possibly with the appropriate `text/html` content type. – Barthy Mar 06 '23 at 14:42
  • Might want to consider adding just a tiny bit of code to your question showing how you are doing the rendering. Keep it simple. A basic `Hello World` would suffice. – Cerad Mar 06 '23 at 14:57
  • There is it ! Thanks you – Noctissei Mar 06 '23 at 15:04
  • It can be instructive to read the source code to see what is going on. AbstractController::render uses twig. End of story. Symfony no longer supports any kind of PHP based templating system. Hasn't for many years. It is going to be up to you to implement whatever system you are being required to use. – Cerad Mar 06 '23 at 15:17
  • Ok simple and effective thanks you ahah – Noctissei Mar 06 '23 at 15:20

0 Answers0