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

[Bug] Can't seem to create a theme #494

Closed
fronbow opened this issue Aug 3, 2023 · 16 comments
Closed

[Bug] Can't seem to create a theme #494

fronbow opened this issue Aug 3, 2023 · 16 comments
Assignees
Labels

Comments

@fronbow
Copy link

fronbow commented Aug 3, 2023

Bug report

What I did

Trying to create a theme so I can override some colour choices of tabler (not found an easy way to do this yet!)
I've gone through the updated docs in (#417) and can't get my theme to be picked up by backpack.
In ui.php I commented out the view_namespace_fallback variable so that I could check if my files were being read and I get a 500 error.

The view: [backpack.ui::blank] was not found in any of the following view paths: [my-theme-folder.::blank ], [ backpack.theme-coreuiv2::blank ], [ backpack.ui::blank]- Called in: /storage/framework/views/9bd51d16f96d06902e0c9283968e1990.php on line: 21

even though I have a blank.blade.php file in the root of the theme folder.

My theme lives in resources -> views -> my-theme-folder.

If I reinstate the view_namespace_fallback variable then the error goes away but I'm left with no customisations, just the fallback theme.

What I've already tried to fix it

Going through the docs on the github issue, moving the theme folder to various different positions in the resources path

Is it a bug in the latest version of Backpack?

Yes, as far as I can tell

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.1.12-1ubuntu4.2 (cli) (built: Jun 28 2023 13:56:12) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
with Zend OPcache v8.1.12-1ubuntu4.2, Copyright (c), by Zend Technologies
with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans

LARAVEL VERSION:

10.17.1.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.1.1
backpack/crud: 6.1.3
backpack/generators: v4.0.2
backpack/logmanager: v5.0.0
backpack/permissionmanager: 7.0.0
backpack/pro: 2.0.10
backpack/theme-coreuiv4: 1.0.5
backpack/theme-tabler: 1.0.6

Cheers for any help/clarification if this isn't a bug!

@fronbow fronbow added the triage label Aug 3, 2023
@karandatwani92 karandatwani92 self-assigned this Aug 5, 2023
@tabacitu
Copy link
Member

tabacitu commented Aug 9, 2023

@fronbow what if you enter your path for both view_namespace and view_namespace_fallback? That should force the system to use your theme, and your theme only, right?

@tabacitu
Copy link
Member

tabacitu commented Aug 9, 2023

I have a custom theme open right now - here's how the file structure looks in mine:

CleanShot 2023-08-09 at 11 14 06

And in config/backpack/ui.php I have:

    /*
    |--------------------------------------------------------------------------
    | Theme (User Interface)
    |--------------------------------------------------------------------------
    */
    // Change the view namespace in order to load a different theme than the one Backpack provides.
    // You can create child themes yourself, by creating a view folder anywhere in your resources/views
    // and choosing that view_namespace instead of the default one. Backpack will load a file from there
    // if it exists, otherwise it will load it from the fallback namespace.

    'view_namespace'          => 'theme-bootstrap.',
    'view_namespace_fallback' => 'backpack.theme-coreuiv4::',

Maybe it helps 🤷‍♂️

@tabacitu tabacitu assigned tabacitu and unassigned karandatwani92 Aug 9, 2023
@tabacitu tabacitu transferred this issue from Laravel-Backpack/CRUD Aug 9, 2023
@tabacitu tabacitu moved this to In Progress in This week Aug 9, 2023
@fronbow
Copy link
Author

fronbow commented Aug 9, 2023

Cheers @tabacitu I'll explore these tomorrow when I get back to my desk and let you know how I get on

@fronbow
Copy link
Author

fronbow commented Aug 10, 2023

@fronbow what if you enter your path for both view_namespace and view_namespace_fallback? That should force the system to use your theme, and your theme only, right?

I get a 500 error

The view: [backpack.ui::blank] was not found in any of the following view paths: [theme-bens.::blank ], [ theme-bens.::blank ], [ backpack.ui::blank]- Called in: /storage/framework/views/9a27ed5633a88f77b9c63f87e16cfb32.php on line: 60

even though I have a blank.blade.php in the root of my theme directory

@fronbow
Copy link
Author

fronbow commented Aug 10, 2023

I have a custom theme open right now - here's how the file structure looks in mine: ....

I've done it like this and everything shows, but backpack isn't reading the templates in my theme directory, it's just defaulting to the fallback theme's files.

So instead of reading my resources/views/theme-bens/dashboard.blade.php
it's reading resources/views/vendor/backpack/theme-tabler/dashboard.blade.php

This is turning out to be a very interesting problem!!!

@pxpm
Copy link
Contributor

pxpm commented Aug 10, 2023

Hey @fronbow This may be interesting yes. Let's see if we can catch up.

I've just tested exactly what you said in two scenarios:
1 - overwrite the dashboard from backpack.
2 - add a new custom view for my theme

So I created the dashboard.blade.php like you did, and a custom_dashboard.blade.php.

The dashboard will overwrite the default dashboard of backpack, and I added a route test for the custom one.

image

image

Is it possible that you have your configs cached or something similar ?

Cheers

@karandatwani92
Copy link
Contributor

Hey @fronbow
You mentioned using the old guide(#417). Just in case we are missing something.
The updated guide might help. https://backpackforlaravel.com/docs/6.x/add-ons-tutorial-how-to-create-a-theme

@fronbow
Copy link
Author

fronbow commented Aug 10, 2023

Hi @pxpm, I just cleared the config:cache and it's still not showing my dashboard, and thanks @karandatwani92 it wasn't updated when I started this, it just referred to the github comment.

I'll go test the updated docs kindly posted by @karandatwani92, hopefully my mileage will be better!!

Cheers All :)

@fronbow
Copy link
Author

fronbow commented Aug 10, 2023

Nope, my mileage is still the same. I've duplicated the folder layout under views, cleared all known caches!, and I even changed the view_namespace_fallback to the same as view_namespace (which still results in the 500 error).
I even checked the file and directory permissions in case linux was being a bit particular!!

The only way I seem to be able to alter the theme view is if I edit the files under resources/views/vendor/backpack/theme-tabler.

I'm now wondering if there's something I'm missing or if I need to fire-up a blank backpack install and test the theme stuff there before adding in all my CRUD files

@fronbow
Copy link
Author

fronbow commented Aug 10, 2023

Hey @fronbow This may be interesting yes. Let's see if we can catch up.

I've just tested exactly what you said in two scenarios: 1 - overwrite the dashboard from backpack. 2 - add a new custom view for my theme

So I created the dashboard.blade.php like you did, and a custom_dashboard.blade.php.

I've just replicated this and got the 500 error again:

The view: [backpack.ui::custom_dashboard.blade.php] was not found in any of the following view paths: [theme-bens.::custom_dashboard.blade.php ], [ backpack.theme-coreuiv4::custom_dashboard.blade.php ], [ backpack.ui::custom_dashboard.blade.php]- Called in: /routes/backpack/custom.php on line: 20

Is it possible that you have your configs cached or something similar ?

I keep clearing everything that can be cleared!!!

Cheers

@pxpm
Copy link
Contributor

pxpm commented Aug 11, 2023

I think I get your error now.

Can you show me what you added in routes/backpack/custom.php ?

I guess you added:
return view(backpack_view('custom_dashboard.blade.php'));
instead of
return view(backpack_view('custom_dashboard')); ?

I tried to raise the same error (giving it a view that doesn't exist) and I noticed that my error didn't contain the .blade.php part.

image

Cheers

@fronbow
Copy link
Author

fronbow commented Aug 11, 2023

You're right, I did add the full filename. I've just changed it to return view(backpack_view('custom_dashboard')); and now I get the

InvalidArgumentException

No hint path defined for [backpack].

page. I'm still confused as to how you and @tabacitu can get your own themes working yet mine fail. My dev machine is linux, so I'm trying to see how windows behaves (though that has its' own set of problems!!)

Cheers

@pxpm
Copy link
Contributor

pxpm commented Aug 11, 2023

I don't think this is related to windows/linux.

We are just serving simple blade files, it's core Laravel functionality. We just check in some more places when you use backpack_view() helper (we check on theme folder first, then in the fallback theme and finally in backpack ui). Nothing sketchy or something that would make any difference between operating systems.

What do you have inside your custom_dashboard.blade.php ? What I am guessing is that you have some call inside it to some view using the backpack hint path that does not exist as the error says. Something like: backpack::some_view or similar.

Cheers

@fronbow
Copy link
Author

fronbow commented Aug 11, 2023

This is the entirety of my routes/backpack/custom.php files:

<?php

use Illuminate\Support\Facades\Route;

// --------------------------
// Custom Backpack Routes
// --------------------------
// This route file is loaded automatically by Backpack\Base.
// Routes you generate using Backpack\Generators will be placed here.

Route::group([
    'prefix'     => config('backpack.base.route_prefix', 'admin'),
    'middleware' => array_merge(
        (array) config('backpack.base.web_middleware', 'web'),
        (array) config('backpack.base.middleware_key', 'admin')
    ),
    'namespace'  => 'App\Http\Controllers\Admin',
], function () { // custom admin routes
    Route::get('test', function () {
        return view(backpack_view('custom_dashboard'));
    });
   }); // this should be the absolute last line of this file

I (@pxpm ) edited this comment to remove all other routes. They are not relevant to this issue.

@fronbow
Copy link
Author

fronbow commented Aug 14, 2023

Hi @pxpm ,
I got back to my work desk today, and everything seems in order, the test page is now showing up, my theme is being correctly read, and I haven't a clue what's changed. I'm going to chalk this one up to those random gremlins that annoy us all from time to time. At least it showed up a glaring bug with basset that only happens on Windows machines which I will report in case anyone else has a tendency to develop on windows (without WSL)

Cheers for all your help

:)

@pxpm
Copy link
Contributor

pxpm commented Aug 14, 2023

No problem @fronbow, anytime. Glad you made it work!

If you enjoy your creation and want to share your theme with others consider releasing it as a package 🙏

Cheers

@pxpm pxpm closed this as completed Aug 14, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in This week Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

4 participants