Controller
$count_em = $this->getDoctrine()->getRepository('AppBundle:St_Jude_Email');
$count_dql = $count_em->createQueryBuilder('c')
->select('count(c.flag)')
->where('c.flag = 0');
$flag_count = $count_dql->getQuery();
$count = $flag_count->getSingleScalarResult();
return $count;
Config.yml
Twig:
globals:
count: '@AppBundle\Controller\countMail'
How to display count which is global in twig?? I'm sorry, I'm new to the symfony and have no idea how to display 'count' in twig. I tried doing {{ count }} , but got error 'An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class AppBundle\Controller\countMail could not be converted to string").'
If you need to return it to Template - return it as an array.
In other cases, if you need use globally, you need to use twig extension, look this documentation.