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>


b. Specific Page View (views/home.blade.php):
@extends('layouts.app')

@section('content')
  @endsection

@section('page-css')
  <link rel="stylesheet" href="{{ asset('css/home.css') }}">  @endsection

@section('page-js')
  <script src="{{ asset('js/home.js') }}"></script>  @endsection


 1. Using Blade Layout Push:


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>


b. Specific Page View (views/home.blade.php):
@extends('layouts.app')

@section('content')
  @endsection

@Push('page-css')
  <link rel="stylesheet" href="{{ asset('css/home.css') }}">  @endsection

@Push('page-js')
  <script src="{{ asset('js/home.js') }}"></script>  @endsection


Comments

Popular posts from this blog

Xpendy Pending

Laravel Join with two coloums