'auto_reload'=>falsein production with Twig, I need to be able to force a recompilation. The easy way would be to clear the cache directory in the deployer when pushing an update, but if I'm micro-optimizing, why not ship built templates as part of the distribution?
The next obvious question is, "How do I make twig compile templates without rendering them?" and it turns out there's a simple answer. The long form
$twig->loadTemplate("name.twig")->render($vars)is the secret:
loadTemplatewrites to the cache if caching is enabled when the template is loaded.
Conceptually, then, it's dead simple: configure Twig how you normally would, list out all your template files, and call
$twig->loadTemplate()on each of them. I believe the minimal solution on POSIX platforms would look like this: