timber / starter-theme

The "_s" for Timber: a dead-simple theme that you can build anything from
MIT License
811 stars 275 forks source link

Timber Error loading template files - existing .twig files not found in spec'd dir path #140

Closed pgnd closed 1 year ago

pgnd commented 1 year ago

i've composer-installed a bedrock-scaffold instance of WP

composer create-project roots/bedrock wp.app
...
wp-cli core version
    6.2

wp-cli cli info
    OS:     Linux 6.2.9-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:31:57 UTC 2023 x86_64
    Shell:  /bin/bash
    PHP binary:     /usr/bin/php
    PHP version:    8.2.4
    php.ini used:   /usr/local/etc/php8/php.ini
    MySQL binary:   /usr/bin/mysql
    MySQL version:  mysql  Ver 15.1 Distrib 10.9.4-MariaDB, for Linux (x86_64) using  EditLine wrapper
    SQL modes:
    WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir:      phar://wp-cli.phar/vendor
    WP_CLI phar path:       /www/wp.app
    WP-CLI packages dir:
    WP-CLI cache dir:       /var/lib/wwwrun/.wp-cli/cache
    WP-CLI global config:
    WP-CLI project config:  /www/wp.app/wp-cli.yml
    WP-CLI version: 2.7.1

i've installed timber & timber/starter-theme,

cd wp.app
composer show | grep -i timber
    timber/timber    2.x-dev 86f9d10    Plugin to write WordPress themes w Objec...

cd wp.app/web/app/themes/timber_s
git branch -a | grep \*
    * 2.x-revert-theme-subfolder
git rev-parse HEAD
    1823e4d0da7e664a674c9c26fc16fa8a3ad069bd

i've created a child theme

cd wp.app/web/app/themes/example-Timber
cat style.css
    /*
    Theme Name:      example-Timber
    Theme URI:       https://example.com/
    Description:     example-Timber Child Theme
    Author:          example.com
    Author URI:      https://example.com/
    Template:        timber_s
    Text Domain:     example-timber-child
    Version:         1.0.0
    */

functions.php includes,

...
<?php
...
$composer_autoload = ABSPATH . '../../vendor/autoload.php';
if ( file_exists( $composer_autoload ) ) {
    require_once $composer_autoload;
    Timber\Timber::init();
}
...
/**
 * Sets the directories (inside your theme) to find .twig files
 */
Timber::$dirname = array( get_stylesheet_directory() . '/views' );

child theme dir structure is

cd wp.app/web/app/themes/example-Timber
tree
    .
    ├── assets
    │   ├── fonts
    │   ├── icons
    │   ├── images
    │   ├── scripts
    │   └── styles
    ├── functions.php
    ├── index.php
    ├── screenshot.png
    ├── static
    │   ├── no-timber.html
    │   └── site.js
    ├── style.css
    └── views
        ├── base.twig
        └── index.twig

it's active

wp-cli theme list --status=parent,active
    +---------------------+--------+--------+---------+
    | name                | status | update | version |
    +---------------------+--------+--------+---------+
    | timber_s            | parent | none   |         |
    | example-Timber      | active | none   | 1.0.0   |
    +---------------------+--------+--------+---------+

where

cat index.php
    <?php

    $context = Timber::context();
    $context['posts'] = '';
    $templates = ['index.twig'];
    if (is_home()) {
        array_unshift($templates, 'front-page.twig', 'home.twig');
    }
    Timber::render($templates, $context);

on nav to home page,

https://example.com

error, in logs,

==> /var/log/nginx/php-fpm.log <==
[09-Apr-2023 15:38:46 UTC] [ Timber ] Error loading your template files: front-page.twig, home.twig, index.twig. Make sure one of these files exists.

Is usage of Timber::$dirname incorrect or not-sufficient? or a bug?

szepeviktor commented 1 year ago

Hello @pgnd 👋🏻

Maybe 2.x-revert-theme-subfolder branch has a bug ... It is just a draft PR #139.

pgnd commented 1 year ago

@szepeviktor

yup.

i just started setting up for a new dev proj, and wanted to test.

seemed to my read that #139, related to the discuss @ https://github.com/timber/timber/pull/2458, was to be a done deal