Environment-driven CDN host for SonataMediaBundle images in wkhtmltopdf generated with Symfony KnpSnappyBundle and TWIG

0 Flares Twitter 0 Facebook 0 LinkedIn 0 0 Flares ×

To display images in wkhtmltopdf you need to enable images:


In addition you have to use absolute paths in your twig template. But sometimes you want to use different path based on your environment. Using assets you can easily do this:


Instead of setting the CDN host statically you can use parameters.yml:

Source: https://github.com/Jolg42/sonata-sandbox/blob/master/app/config/parameters.yml.sample#L30


Then in your sonata_media.yml :

Source: https://github.com/Jolg42/sonata-sandbox/blob/master/app/config/sonata/sonata_media.yml#L33


Now you can use the Sonata Media helpers to display the images:


Web Deviloper