nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.5k stars 954 forks source link

how to extend new layout? #1860

Closed srakl closed 2 weeks ago

srakl commented 4 months ago

in my module view i have these

Modules/Abc/Resources/views/layouts/pdf.blade.php and in it i have this

<!DOCTYPE html>
<html lang="{{ session()->get('locale') ?? app()->getLocale() }}">

<head itemscope itemtype="http://schema.org/WebSite">
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.svg') }}" />
    <title>@yield('title')</title>
</head>
<body>
    @yield('content')
</body>
</html>

and in my view

Modules/Abc/Resources/views/pdf/pdf.blade.php i have this

@extends('abc::layouts.pdf')

@section('content')
kkajdakjsdlasjdaljdlasjdlaajdlaj
@endsection

when i go to the page, the page loads but not using the layout. any ideas why?

ahmillat commented 4 months ago

The issue might stem from how Blade is resolving the view paths and namespaces in Laravel: Can you please make sure below things:

Register Views in Service Provider: Ensure your module's service provider correctly registers the views.

   // AbcServiceProvider.php
   public function boot()
   {
       $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'abc');
   }

Use Correct Blade Directive: Ensure you extend the layout correctly in pdf.blade.php.

   @extends('abc::layouts.pdf')

Clear View Cache: Clear the view cache to ensure changes are reflected.

   php artisan view:clear

Debug Layout: Add a test message in your layout to ensure it loads.

   <body>
       <h1>Layout is loading</h1>
       @yield('content')
   </body>

Route and Controller: Ensure your route and controller return the correct view.

   // web.php
   Route::get('/pdf', 'PdfController@showPdf');

   // PdfController.php
   public function showPdf()
   {
       return view('abc::pdf.pdf');
   }