Search code examples
emailsymfonytwigassets

Absolute path for assets in email without having a request object in Symfony2


I'm sending emails using a Symfony2 command that is triggered by a cron job periodically. In the footer of the email I want to show the logo of the company. I know that in the case of emails, I have to use absolute paths for the images, and normally I would do something like this:

{% set abs_url = app.request.scheme ~'://' ~ app.request.httpHost %}
<img src="{{ abs_url ~ asset('bundles/common/images/logo_mialarma.png') }}">

But when the twig template of the email is being called by a command that is in turn called by a cron job, there isn't such request object.

How can I create the absolute path of the asset in this situation?


Solution

  • Create a configuration parameter to set your app's domain to.