How to render Twig template from database in symfony2

前端 未结 11 1019
闹比i
闹比i 2020-12-08 04:21

I\'m working on application written in symfony2 and I want to send email after some action/event... the problem is, that the users can define something like \"email template

11条回答
  •  孤街浪徒
    2020-12-08 05:03

    The best way to do it is to use template_from_string twig function.

    {{ include(template_from_string("Hello {{ name }}")) }}
    {{ include(template_from_string(page.template)) }}
    

    See documentation of template_from_string

    See why it is not a good idea to use Twig_Loader_Chain or Twig_Loader_String for that purpose on this github issue by stof.

提交回复
热议问题