How to render an object instead of array, like we usually do?
echo $twig->render('index.html', array('name' => 'Fabien'));
The render()
function does not accept an object.
Is there any way to render the object directly?.
And I do not mean an "objectToArray" solution.
The second parameter of the method render take an array for transport data to the view, so you simply put your object as value of the array with a specified key. Something like this:
$object = new People()
$object->setName('Fabien');
echo $twig->render('index.html', array('obj' => $object));
And use in the template as
{{ obj.name }}
Hope this help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With