How to render Twig template from database in symfony2

前端 未结 11 999
闹比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:08

    This work for me:

    $loader = new \Twig\Loader\ArrayLoader([
        'Temp_File.html' => 'Hello {{ name }}!',
    ]);
    $twig = new \Twig\Environment($loader);
    
    echo $twig->render('Temp_File.html', ['name' => 'Fabien']);
    

    https://twig.symfony.com/doc/2.x/api.html

提交回复
热议问题