Wednesday, March 8, 2017

Laravel ajax loading a sub-view

Firstly, sorry for my bad English.


Assume I have this master.blade.php :
<html>
<head>
    <title>@yield('title')</title>
    @include('layouts.panel.head')
    @yield('head')
</head>
<body>
    @include('layouts.panel.header')
    @yield('content')
    @yield('scripts')
</body>
</html>

And a Sub-View like users-list.blade.php:

@extends('layouts.panel.master')
@section('head')
  <link href="/css/datatables.min.css" rel="stylesheet" />
@stop
@section('title') Users List @stop
@section('content')
    <div class="row">
        <div class="col-md-12">
            <table id="UsersTable">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>Username</th>
                    <th>Email</th>
                </tr>
                </thead>
                <tbody>
                  blah blah blah...
                </tbody>
            </table>
        </div>
    </div>
@stop
@section('script')
  <script src="/js/dataTables.min.js"></script>
@stop

I need to load the sub-view users-list.blade.php by ajax content loading.

The problem is where users-list.blade.php returns whole page! (because it extends master.blade.php.

Is there any way to just load @section parts without extending master page ?

Each sub-view has separate @section('head') and @section('content') and @section('script').

I hope I've explained clear enough.

Any helps would be great appreciated.



via Hamed Kamrava

Advertisement