在 twig 中输出 webcal-download-url 的最佳方法 [英] Best way to output a webcal-download-url in twig
问题描述
我想在 Twig 中像这样生成一个 URL(用例是可订阅的日历):
I would like to generate an URL in Twig like this (usecase is subscribable calendar):
webcal://subdomain.mydomain.com/calendar.ics
文件名通过配置中的 twig: global: ...
和 twig 中的 {{ filename }}
给出.
我的问题是,使用 {{ url('index') }}
生成的 URL 使用 http://
作为协议,但我需要 webcal://
.
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.
我正在寻找正确的方法.最后的机会是通过 twig-global 传递洞网址.
I am searching for the proper way. Last chance would be to pass the hole url via twig-global.
推荐答案
可能有更清晰的方法,但我之前已经成功使用过这样的东西:
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.
这篇关于在 twig 中输出 webcal-download-url 的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!