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',
    ]);
}
5
  • Hey Noctissei, does this answer 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. Commented Mar 6, 2023 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. Commented Mar 6, 2023 at 14:57
  • There is it ! Thanks you Commented Mar 6, 2023 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. Commented Mar 6, 2023 at 15:17
  • Ok simple and effective thanks you ahah Commented Mar 6, 2023 at 15:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.