Shipu / themevel

Theme and asset management for laravel
Creative Commons Zero v1.0 Universal
347 stars 67 forks source link

What about template error pages? #16

Closed enverarslan closed 6 years ago

enverarslan commented 6 years ago

We can override laravel error pages with putting error files(404.blade.php, 500.blade.php etc.) into "resources/views/errors" folder.

I put error pages in my template folder(etc themes/dashboard/views/errors/404.blade.php) but it didn't work.

How can override error pages in template views?

I know its about exception handling, we must add template path in view config paths.

But we need proper implementation.

image

Shipu commented 6 years ago

Yes manually you can fixed it. I will add theme error pages in next release so please wait for few days.

ivenspontes commented 6 years ago

any news?

dariusj18 commented 6 years ago

It seems to me that there is the errors namespace and when the theme is set it just needs to add itself to the errors namespace.

enverarslan commented 6 years ago

Hey guys, I think this solved.

I opened issue in older laravel version, but solution is same.

In Laravel 5.6 replacing views error namespace job separated from renderHttpException function. This function named registerErrorViewPaths().

This screenshot given from source code in (vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php)

screenshot_1

We only override registerErrorViewPaths() function in (app/Exceptions/Handler.php) like this:

/**
     * Register the error template hint paths.
     *
     * @return void
     */
    protected function registerErrorViewPaths()
    {
        $current_theme_path = Theme::getThemeInfo(Theme::current())->get('path')."/views";
        $paths = collect($current_theme_path);

        View::replaceNamespace('errors', $paths->map(function ($path) {
            return "{$path}/errors";
        })->all());
    }

But finding current theme in this situation gives us null result. Because router not found any endpoint and there is no middleware worked for us. So we couldn't set any theme. We can set theme in render function in "app/Exceptions/Handler.php" file:

/**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Exception $exception
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function render($request, Exception $exception)
    {   
        // We set theme for finding current theme view files.
        Theme::set('theme-name');
        ...
     }