symfony - How do I render a controller returned image in a Twig template -
in order protect images uploaded customers store them in "app/data" , retrieve them using following controller:
use symfony\bundle\frameworkbundle\controller\controller; use symfony\component\httpfoundation\binaryfileresponse; use symfony\component\httpfoundation\responseheaderbag;  class assetscontroller extends controller {     ...     public function serveprofilepictureaction() {         ...         $response = new binaryfileresponse($filepath);         $response->headers->set('content-type', 'image/' . $this->getimagemimetype($filepath));         $response->setcontentdisposition(responseheaderbag::disposition_inline);          return $response;     } }   the controller works fine , serves image if call using route. how embed image in twig template? tried
{{ render(controller('securedassetsbundle:assets:serveprofilepicture')) }}   but doesn't anything.
thanks!
you have embed image tag browser fetch you:
<img src="{{ path('serveprofilepictureroute') }}" alt="your profile picture" />   where serveprofilepictureroute whatever you've named profile picture route.
Comments
Post a Comment