Best way to output a webcal-download-url in twig

隐身守侯 提交于 2019-12-11 05:08:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21161771/best-way-to-output-a-webcal-download-url-in-twig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!