There may be a clearer way, but I've successfully used something like this before:
{{ url("my-route")|replace({ "http:" : "webcal:" }) }}
This generates an absolute url to your route then replaces the scheme.
Question
I would like to generate an URL in Twig like this (usecase is subscribable calendar):
webcal://subdomain.mydomain.com/calendar.ics
The filename is given via twig: global: ...
in config an {{ filename }}
in twig.
My problem is, that using {{ url('index') }}
the generated URL uses http://
as protocol, but I need webcal://
.
I also see no way to fix this by using schemes, because this protocol is special for just this case and none of the routes generated by that 'Index-'Controller.
I am searching for the proper way. Last chance would be to pass the hole url via twig-global.
Solution
There may be a clearer way, but I've successfully used something like this before:
{{ url("my-route")|replace({ "http:" : "webcal:" }) }}
This generates an absolute url to your route then replaces the scheme.