Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timber Child Theme #1665

Closed
JakeHenshall opened this issue Feb 19, 2018 · 0 comments
Closed

Timber Child Theme #1665

JakeHenshall opened this issue Feb 19, 2018 · 0 comments

Comments

@JakeHenshall
Copy link

Is this a support or usage question? Please post to StackOverflow using the Timber tag

Expected behavior

To be able to Initialise Timber from the Parent Theme and have the Child theme use it.

Actual behavior

Fatal error: Uncaught Error: Class 'Timber\Timber' not found in /Users/jake/Code/wp/wp-content/themes/framework-child/functions.php:23 Stack trace: #0 /Users/jake/Code/wp/wp-settings.php(426): include() #1 /Users/jake/Code/wp/wp-config.php(89): require_once('/Users/jake...') #2 /Users/jake/Code/wp/wp-load.php(37): require_once('/Users/jake...') #3 /Users/jake/Code/wp/wp-admin/admin.php(31): require_once('/Users/jake...') #4 /Users/jake/Code/wp/wp-admin/index.php(10): require_once('/Users/jake...') #5 {main} thrown in /Users/jake/Code/wp/wp-content/themes/framework-child/functions.php on line 23

Steps to reproduce behavior

Parent functions.php:

if (file_exists($composer = DIR . '/vendor/autoload.php')) {
require $composer;
}

// Initialise Timber
$timber = new \Timber\Timber();
require_once DIR . '/app/timber.php';

Child functions.php:

if (file_exists($composer = DIR . '/vendor/autoload.php')) {
require $composer;
}

// Initialise Timber
$timber = new \Timber\Timber();
require_once DIR . '/app/timber.php';

Both Parent & Child app/timber.php

$timber = new \Timber\Timber();

Timber::$dirname = array('resources/views');

class Framework extends Timber\Site
{
public function __construct()
{
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );

    add_filter('timber_context', array($this, 'add_to_context'));
    add_filter('get_twig', array($this, 'add_to_twig'));
    add_action('init', array($this, 'register_post_types'));
    add_action('init', array($this, 'register_taxonomies'));
    parent::__construct();
}

public function register_post_types()
{
    //this is where you can register custom post types
}

public function register_taxonomies()
{
    //this is where you can register custom taxonomies
}

public function add_to_context($context)
{
    $context['menu'] = new TimberMenu();
    $context['site'] = $this;
    return $context;
}

public function add_to_twig($twig)
{
    /* this is where you can add your own functions to twig */
    $twig->addExtension(new Twig_Extension_StringLoader());
    return $twig;
}

}

new Framework();

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

WordPress 4.9.4 PHP 7.1 Timber 1.7.0

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

Composer/Packagist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant