Disable Twig compilation cache for a particular template

后端 未结 1 699
粉色の甜心
粉色の甜心 2021-01-12 06:19

Is there a way to disable the Twig compilation cache for a particular template?

I\'m using Twig for my email templates. When someone updates these templates, they ar

相关标签:
1条回答
  • 2021-01-12 06:45

    I think your answer might be not in disabling cache for a specific template, but clearing the cache for a template after it's been updated. I haven't tested the code below, but it seems reasonable. Play around with it a bit

    In your action/service that saves a template (after the template has been saved):

    $fileCache = $this->container->get('twig')->getCacheFilename('AcmeDemoBundle:Default:index.html.twig');
    
    if (is_file($fileCache)) {
        @unlink($fileCache);
    }
    

    For more information, check out how twig cache files are handed in /vendor/twig/twig/lib/Twig/Environment.php (\Twig_Environment) -- method loadTemplate().

    0 讨论(0)
提交回复
热议问题