Ad
Check Existence Of Twig Template In Timber
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.
Ad
Answer
$loader = new Timber\Loader;
if ( $loader->get_loader()->exists( 'template-name.twig' ) ) {
// file exists
}
Thank you @Jeto for the trail.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad