How to use absolute path in twig functions

后端 未结 9 1099
情话喂你
情话喂你 2020-12-04 16:35

I have an application with Symfony2 (2.2). When I want to send a mail, I\'m having trouble with the paths, which are all relative paths and obviously aren\'t working inside

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 16:43

    For Symfony 2.7 and newer

    See this answer here.

    1st working option

    {{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset('bundles/acmedemo/images/search.png') }}
    

    2nd working option - preferred

    Just made a quick test with a clean new Symfony copy. There is also another option which combines scheme and httpHost:

    {{ app.request.getSchemeAndHttpHost() ~ asset('bundles/acmedemo/images/search.png') }}
    {# outputs #}
    {# http://localhost/Symfony/web/bundles/acmedemo/css/demo.css  #}
    

提交回复
热议问题