Void Floyd
Void Floyd

Reputation: 171

Symfony2 does not render php templates correctly

I have a problem with rendering PHP templates instead Twig templates in Symfony2. The problem is Symfony for some reason does not interpret PHP code in template. Instead of interpreting PHP blocks of code, Symfony renders them simply as plain text. I try to follow to the documentation and render form to template like so. When I write in controller

return $this->render('MyStudyBundle:Default:new.html.twig', array(
    'form' => $form->createView(),
));

form loads as I expect. But when I change "new.html.twig" to "new.html.php" and try to render form in php template - as a result I have HTML page, where php code simply showed like plain text. The question is why Symfony does not interpret blocks of php code in php templates?

Upvotes: 0

Views: 2100

Answers (2)

Motolola
Motolola

Reputation: 368

You need to enable PHP template engine fron the app/config.yml file, and save your template as .php and not .twig

Upvotes: 0

Samy Dindane
Samy Dindane

Reputation: 18706

You need to enable PHP templating engine.

In your app/config/config.yml:

framework:
     templating:    { engines: ['twig', 'php'] }

This might be helpful to you: How to use PHP instead of Twig for Templates.

Upvotes: 2

Related Questions