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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -