Is there a way in Timber to check to see if a Twig template exists before attempting to render one?
I have seen SO answers for how to accomplish this in Symfony ($this->get('twig')->getLoader()->exists('AcmeDemoBundle:Foo:bar.html.twig')
), but I need a Timber-specific answer.
If not, I can always use PHP-specific
if ( get_stylesheet_directory() . '/templates/template-name.twig' ) { ... }
but I thought I'd see if anyone knew of a Timber method to accomplish this.
Timber\Loader
has aget_loader
method that should return the Twig loader instance (which you can then callexists
on). – Jeto