ekandreas / bladerunner

WordPress plugin for Laravel Blade templating DEPRECATED
http://bladerunner.elseif.se
12 stars 1 forks source link

Custom Template Path not Working #68

Closed nathanaelphilip closed 6 years ago

nathanaelphilip commented 6 years ago

Hi hi! Back again :)

add_filter('bladerunner/template/bladepath', function ($paths) {
    if (!is_array($paths)) {
      $paths = [$paths];
    }

    $paths[] = get_template_directory() . '/app';

    return $paths;
  });

I have a views folder inside app, so it’s THEME/app/views and inside that, i have index.blade.php

i can’t get bladerunner to recognize this template :/. It does work if I just put the views folder directly inside the THEME folder.

Thanks!

ekandreas commented 6 years ago
add_filter('bladerunner/template/bladepath', function($paths) {
    if(!is_array($paths)) $paths = [$paths];
    $paths[] = get_template_directory() . "/app/views";
    return $paths;
});
nathanaelphilip commented 6 years ago

i tried that as well, but I’ll try again!

nathanaelphilip commented 6 years ago

this is the error i get:

Fatal error: Uncaught InvalidArgumentException: View [views.index] not found. in /app/vendor/illuminate/view/FileViewFinder.php:137 Stack trace: #0 /app/vendor/illuminate/view/FileViewFinder.php(79): Illuminate\View\FileViewFinder->findInPaths('views.index', Array) #1 /app/vendor/illuminate/view/Factory.php(128): Illuminate\View\FileViewFinder->find('views.index') #2 [internal function]: Illuminate\View\Factory->make('views.index', Array, Array) #3 /app/content/plugins/bladerunner/src/Blade.php(127): call_user_func_array(Array, Array) #4 /app/content/plugins/bladerunner/src/Blade.php(51): Bladerunner\Blade->__call('make', Array) #5 /app/content/plugins/bladerunner/globals/helpers.php(21): Bladerunner\Blade->render('views.index', Array) #6 /app/content/plugins/bladerunner/globals/filters.php(73): view('views.index', Array) #7 /app/cms/wp-includes/class-wp-hook.php(298): {closure}('/app/content/th...') #8 /app/cms/wp-includes/plugin.php(203): WP_Hook->apply_filters('/app/content/th...', Array) #9 /app/cms/wp-includes/templa in /app/vendor/illuminate/view/FileViewFinder.php on line 137
ekandreas commented 6 years ago

Can you provide me with the theme code?

nathanaelphilip commented 6 years ago

strt.zip

ekandreas commented 6 years ago

And if you put this in index.php?

<?php
    echo view('app.views.index');

I will take a look more close soon and respond to you.

nathanaelphilip commented 6 years ago

i put the above code in the index.php and i’m still getting a fatal error

ekandreas commented 6 years ago

You can go two ways with quirky folders in this case:

  1. Put echo view('app.views.index'); or
  2. Place a template override in the controller to the right template, eg:
    
    <?php
    // file: app/controllers/index.php with controllers path set

use Bladerunner\Controller;

class IndexController extends Controller { protected $template = 'app.views.index';

public function hello()
{
    return 'hello world';
}

}


So you have to choose if you would like to use controllers or only views.
I think that you have a conflict now with both techniques at the same time :-)
nathanaelphilip commented 6 years ago

should i remove this:

add_filter('bladerunner/template/bladepath', function($paths) {
    if(!is_array($paths)) $paths = [$paths];
    $paths[] = get_template_directory() . "/app/views";
    return $paths;
});

?

ekandreas commented 6 years ago

It depends! the template/bladepath is made for plugin dev. Go for the controller and set the template path in each controller instead! So much cleaner and easy to understand!

nathanaelphilip commented 6 years ago

oh ok – i didn’t know that! Thanks for your help!

ekandreas commented 6 years ago

Hope you are getting forward and get use of the plugin. Blade is a great templating language.

nathanaelphilip commented 6 years ago

yeah! i was going to just use the default structure if needed, but this works for me. it’ll make things a bit more explicit!