At your command:
$this->render('template.html.twig', [ 'scheme' => 'https', 'host' => 'example.com', ]);
In your template:
{% if app.request is defined %}{{ app.request.scheme }}{% else %}{{ scheme|default('http') }}{% endif %}
Personally, I would divert the generation of img src to a function, instead of hard-coding this logic everywhere in templates.
source share