Get a Twig file by relative path then include it in base.html.twig in app folder

php symfony twig symfony-2.3 symfony-3.3

264 观看

1回复

27 作者的声誉

This is my iframe code in my base template:

<iframe id="main" src="{{ app.request.getBaseURL() }}/include/main.html.twig"></iframe>

In my app folder I have another folder named include/ that has a twig file named main.html.twig.

I want to include the main.html.twig file in src like this:

<iframe id="main" src="/include/main.html.twig"></iframe>
作者: programmer java 的来源 发布者: 2017 年 12 月 27 日

回应 1


1

1407 作者的声誉

决定

It won't work this way . You cannot/shouldn't directly link to twig files. That is what you need to do :

  • Create new action in controller , that will render that main.html.twig, and name it. (read about routing and @Route annotation)
  • in iframe you need to use src="{{ path('route_name_to created action') }}"
作者: Michał G 发布者: 2017 年 12 月 28 日
32x32