Add Css And Js Files on Specific Page In laravel
1. Using Blade Layout Sections:
Laravel's Blade templating engine provides a powerful way to manage layouts and include specific content on different pages. Here's how to achieve this:
a. Base Layout (layouts/app.blade.php
):
<!DOCTYPE html> <html> <head> <title>My Website</title> @yield('page-css') <link rel="stylesheet" href="{{ asset('css/app.css') }}"> </head> <body> @include('partials.header') <main>@yield('content')</main> @include('partials.footer') @yield('page-js') <script src="{{ asset('js/app.js') }}"></script> </body> </html>
views/home.blade.php
):a. Base Layout (layouts/app.blade.php
):
<!DOCTYPE html> <html> <head> <title>My Website</title> @Stck('page-css') <link rel="stylesheet" href="{{ asset('css/app.css') }}"> </head> <body> @include('partials.header') <main>@yield('content')</main> @include('partials.footer') @stack('page-js') <script src="{{ asset('js/app.js') }}"></script> </body> </html>
views/home.blade.php
):
Comments
Post a Comment