timber / timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine
https://timber.github.io/docs/
MIT License
5.53k stars 514 forks source link

Failed to load template for single-posttype.twig (v1.0) #975

Closed minthemiddle closed 8 years ago

minthemiddle commented 8 years ago

Expected behavior

In version 0.22.5 I could load a template for all custom posttypes via function.php and the following settings:

(single.php)

$post = Timber::get_post('TimberPost');
(...)
Timber::render(array('single-' . $post->post_type . '.twig', 'single.twig'), $data);

Actual behavior

With version 1.0, I get with my custom posttype unternehmen such as in this link the following error:

PHP Fatal error: Uncaught Twig_Error_Loader: Unable to find template "single-.twig"

What version of WordPress, PHP and Timber are you using?

Wordpress 4.5.1, Timber 0.22.5 (no error), Timber 1.0 (breaks custom posttype twig loader)

connorjburton commented 8 years ago

Hi @minthemiddle - this is probably due to us removing some functionality to do with 'guessing' what class you want. Could you please try the following:

$post = Timber::get_post(array(), 'TimberPost');

minthemiddle commented 8 years ago

Ok, let me test this locally.

connorjburton commented 8 years ago

Any luck @minthemiddle ?

connorjburton commented 8 years ago

Actually try, TimberPost(false, 'TimberPost') - I am not sure what you are trying to do with this code however? The first parameter should be your query, and the second parameter is already \Timber\Post by default. So this doesn't seem to be doing anything?

connorjburton commented 8 years ago

You could actually just remove your call completely and it will work, as $post will already be defined by wordpress in single.php

I'm going to close this as the Timber::get_post call you are doing isn't valid