tonik / theme

Tonik is a WordPress Starter Theme which aims to modernize, organize and enhance some aspects of WordPress theme development.
http://labs.tonik.pl/theme/
MIT License
1.33k stars 140 forks source link

Unexpected behaviour of template() #66

Closed lhermann closed 6 years ago

lhermann commented 6 years ago

Hi guys, thank you first of all for your awsome theme framework!

In my single.php controller I am doing this:

use function AppTheme\template;
template( [ 'single', get_query_var( 'post_type' ) ] );

Expected behaviour

When I request /books/ for a custom post type books I expect it to first look for single-books.tpl.php, then for single.tpl.php, then throw an error.

Actual behaviour

It looks for single-books.tpl.php, but then it looks for single-.tpl.php. The dash shouldn't be in there.

See here:

Fatal error: Uncaught Tonik\Gin\Foundation\Exception\FileNotFoundException: Template file [resources/templates/single-.tpl.php] cannot be located. in /app/themefiles/vendor/tonik/gin/src/Gin/Template/Template.php on line 54```
jedrzejchalubek commented 6 years ago

This happens when you pass an empty string as a template name. We have to additionally check for an empty string.

template(['single', '']);

For now, I would recommend you to create a post type specific controllers or check for an empty string at get_query_var.

Thanks for the greatly exemplary bug report :)

jedrzejchalubek commented 6 years ago

Fixed with tonik/gin:v2.0.3 release

lhermann commented 6 years ago

Thank you for this quick response. Applied the update and can confirm that it is fixed!