From 09a7ce7e3745641a2458bed59de11d8b3942de26 Mon Sep 17 00:00:00 2001 From: Jared Novack Date: Mon, 13 Apr 2020 20:21:48 -0400 Subject: [PATCH] Tweak error output and confirm with test --- lib/Helper.php | 2 +- lib/Timber.php | 5 ++++- tests/test-timber-loader.php | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Helper.php b/lib/Helper.php index c0492c6c0..6ee80cf9c 100644 --- a/lib/Helper.php +++ b/lib/Helper.php @@ -200,7 +200,7 @@ public static function error_log( $error ) { if ( is_object($error) || is_array($error) ) { $error = print_r($error, true); } - return error_log('[ Timber ]'.$error); + return error_log('[ Timber ] '.$error); } /** diff --git a/lib/Timber.php b/lib/Timber.php index e3263a115..b28d339d7 100644 --- a/lib/Timber.php +++ b/lib/Timber.php @@ -333,7 +333,10 @@ public static function compile( $filenames, $data = array(), $expires = false, $ $output = $loader->render($file, $data, $expires, $cache_mode); } else { - Helper::error_log( 'Error loading your template file, make sure the file exists.' ); + if ( is_array($filenames) ) { + $filenames = implode(", ", $filenames); + } + Helper::error_log( 'Error loading your template files: '.$filenames.'. Make sure one of these files exists.' ); } do_action('timber_compile_done'); diff --git a/tests/test-timber-loader.php b/tests/test-timber-loader.php index c8b90e2be..55ae0f4af 100644 --- a/tests/test-timber-loader.php +++ b/tests/test-timber-loader.php @@ -21,6 +21,11 @@ function testBogusTemplates() { $this->assertFalse($str); } + function testTemplateChainWithMissingTwigFiles() { + $str = Timber::compile( array('assets/lonestar.twig', 'assets/single.twig') ); + $this->assertEquals('I am single.twig', trim($str)); + } + function testWhitespaceTrimForTemplate(){ $str = Timber::compile('assets/single.twig ', array()); $this->assertEquals('I am single.twig', trim($str));