Search code examples
jsonsymfonypropel

Send array list to Twig View without headers in Symfony 2


I need help sending query list to Twig without headers. I have already query my data and I am stuck. I had to have this data in JSON structure.

This is name of my root: 'AdminBundle:Note:viewPdf.html.twig' And here is name of query class in propel - it is empty now: MnNoteCommentQuery.

Here is my code:

$noteQuery = MnNoteCommentQuery::create()->find();
$responsed = new JSonResponse($noteQuery);
return $this->render('AdminBundle:Note:viewPdf.html.twig', array('notes' => $responsed));

Solution

  • Just use json_encode in twig

    return $this->render('AdminBundle:Note:viewPdf.html.twig', array('notes' => $notes));
    

    Twig:

    {{ notes | json_encode() }}
    

    You can customize json representation by implementing JsonSerializable interface