Skip to content

Commit

Permalink
Tweak error output and confirm with test
Browse files Browse the repository at this point in the history
  • Loading branch information
jarednova committed Apr 14, 2020
1 parent 752f5e2 commit 09a7ce7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/Timber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions tests/test-timber-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 09a7ce7

Please sign in to comment.