class DefaultController extends Controller { public function indexAction($page, $name) { return $this->render('default/new.html.php' // , array( // $name => 'bob' // ) ); } }
new.html.php
<p>Welcome to the index <?= $name; ?></p>
When I use this code it is returning an error message.
But,
<p>Welcome to the index {{ name }}
this returns me correct output.
I want to use .html.php
instead of .html.twig
I am going through this https://symfony.com/doc/3.4/templating/PHP.html
routing.yml
app: path: /dd defaults: _controller: AppBundle:Default:index page: 1 name: "bob"
config.yml
framework: # ... templating: engines: ['twig', 'php']
Note: I am using ubuntu16.04 and Symfony 3.4
Advertisement
Answer
Tried locally according to Symfony documentation:
/** * @Route("/test", name="test_route") */ public function test() { return $this->render( 'test.html.php', [ 'test_var' => 'Hello test', ] ); }
My test.html.php
:
<?php echo $test_var;
This outputs Hello test
.
PS: Tried get_defined_vars();
, the variable should be seen there.