Laravel-adminlte: QUESTION: Split page layout into differents blade components?

Created on 23 Apr 2020  ยท  4Comments  ยท  Source: jeroennoten/Laravel-AdminLTE

Hi, on my local project I was working on splitting the page layout into different components (_top navbar, left sidebar, right sidebar, footer, etc..._), creating multiples blade templates for each one of these and then include they on the page layout in order to clean and make it easy to maintain. As an example, this is how the page.blade.php file looks now:

@extends('adminlte::master')

@section('adminlte_css')
    @stack('css')
    @yield('css')
@stop

@section('classes_body', $adminlte->getBodyClasses())

@section('body_data', $adminlte->getBodyData())

@php( $logout_url = View::getSection('logout_url') ?? config('adminlte.logout_url', 'logout') )
@php( $profile_url = View::getSection('profile_url') ?? config('adminlte.profile_url', 'logout') )
@php( $dashboard_url = View::getSection('dashboard_url') ?? config('adminlte.dashboard_url', 'home') )

@if (config('adminlte.use_route_url', false))
    @php( $logout_url = $logout_url ? route($logout_url) : '' )
    @php( $profile_url = $profile_url ? route($profile_url) : '' )
    @php( $dashboard_url = $dashboard_url ? route($dashboard_url) : '' )
@else
    @php( $logout_url = $logout_url ? url($logout_url) : '' )
    @php( $profile_url = $profile_url ? url($profile_url) : '' )
    @php( $dashboard_url = $dashboard_url ? url($dashboard_url) : '' )
@endif

@section('body')
    <div class="wrapper">

        {{-- Top Navbar --}}
        @if(config('adminlte.layout_topnav') || View::getSection('layout_topnav'))
            @include('adminlte::partials.navbar.navbar-layout-topnav')
        @else
            @include('adminlte::partials.navbar.navbar')
        @endif

        {{-- Left Main Sidebar --}}
        @if(!config('adminlte.layout_topnav') && !View::getSection('layout_topnav'))
            @include('adminlte::partials.sidebar.left-sidebar')
        @endif

        {{-- Content Wrapper --}}
        <div class="content-wrapper">
            @if(config('adminlte.layout_topnav') || View::getSection('layout_topnav'))
                <div class="container">
            @endif

            {{-- Content Header --}}
            <div class="content-header">
                <div class="{{config('adminlte.classes_content_header', 'container-fluid')}}">
                    @yield('content_header')
                </div>
            </div>

            {{-- Main Content --}}
            <div class="content">
                <div class="{{config('adminlte.classes_content', 'container-fluid')}}">
                    @yield('content')
                </div>
            </div>

            @if(config('adminlte.layout_topnav') || View::getSection('layout_topnav'))
                </div>
            @endif
        </div>

        {{-- Footer --}}
        @hasSection('footer')
            @include('adminlte::partials.footer.footer')
        @endif

        {{-- Right Control Sidebar --}}
        @if(config('adminlte.right_sidebar'))
            @include('adminlte::partials.sidebar.right-sidebar')
        @endif

    </div>
@stop

@section('adminlte_js')
    <script src="{{ asset('vendor/adminlte/dist/js/adminlte.min.js') }}"></script>
    @stack('js')
    @yield('js')
@stop

And this is the how adminlte::partials.navbar.navbar looks like:

<nav class="main-header navbar
    {{ config('adminlte.classes_topnav_nav', 'navbar-expand-md') }}
    {{ config('adminlte.classes_topnav', 'navbar-white navbar-light') }}">

    {{-- Navbar left links --}}
    <ul class="navbar-nav">
        {{-- Left sidebar toggler link --}}
        @include('adminlte::partials.navbar.left-sidebar-link')

        @each('adminlte::partials.menu-item-top-nav-left', $adminlte->menu(), 'item')
        @yield('content_top_nav_left')
    </ul>

    {{-- Navbar right links --}}
    <ul class="navbar-nav ml-auto">
        @yield('content_top_nav_right')
        @each('adminlte::partials.menu-item-top-nav-right', $adminlte->menu(), 'item')

        {{-- User menu links --}}
        @if(Auth::user())
            @if(config('adminlte.usermenu_enabled'))
                @include('adminlte::partials.navbar.dropdown-user-menu')
            @else
                @include('adminlte::partials.navbar.logout-link')
            @endif
        @endif

        {{-- Right sidebar toggler link --}}
        @if(config('adminlte.right_sidebar'))
            @include('adminlte::partials.navbar.right-sidebar-link')
        @endif
    </ul>

</nav>

Also, this is the current structure of the resources/views folder:

โ”œโ”€โ”€ login.blade.php
โ”œโ”€โ”€ master.blade.php
โ”œโ”€โ”€ page.blade.php
โ”œโ”€โ”€ partials
โ”‚ย ย  โ”œโ”€โ”€ common
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ brand-logo-xl.blade.php
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ brand-logo-xs.blade.php
โ”‚ย ย  โ”œโ”€โ”€ footer
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ footer.blade.php
โ”‚ย ย  โ”œโ”€โ”€ menu-item.blade.php
โ”‚ย ย  โ”œโ”€โ”€ menu-item-sub-top-nav.blade.php
โ”‚ย ย  โ”œโ”€โ”€ menu-item-top-nav.blade.php
โ”‚ย ย  โ”œโ”€โ”€ menu-item-top-nav-left.blade.php
โ”‚ย ย  โ”œโ”€โ”€ menu-item-top-nav-right.blade.php
โ”‚ย ย  โ”œโ”€โ”€ menu-item-top-nav-user.blade.php
โ”‚ย ย  โ”œโ”€โ”€ navbar
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ dropdown-user-menu.blade.php
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ left-sidebar-link.blade.php
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ logout-link.blade.php
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ navbar.blade.php
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ navbar-layout-topnav.blade.php
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ right-sidebar-link.blade.php
โ”‚ย ย  โ””โ”€โ”€ sidebar
โ”‚ย ย      โ”œโ”€โ”€ left-sidebar.blade.php
โ”‚ย ย      โ””โ”€โ”€ right-sidebar.blade.php
โ”œโ”€โ”€ passwords
โ”‚ย ย  โ”œโ”€โ”€ confirm.blade.php
โ”‚ย ย  โ”œโ”€โ”€ email.blade.php
โ”‚ย ย  โ””โ”€โ”€ reset.blade.php
โ”œโ”€โ”€ plugins.blade.php
โ”œโ”€โ”€ register.blade.php
โ””โ”€โ”€ verify.blade.php

So, the question is if you are interested on these changes. In the case you are interested, I can open a pull request for it. Thanks!

All 4 comments

+1
More views are easier to override in case other developers need to customize it.

Think its a good thing and in my perspective, its easier to maintain.

I would say the same like @andcarpi, it's a good idea and easier to maintain for further changes/adds.

Thanks for the feedback, I'm going to submit a PR for this changes later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shidersz picture Shidersz  ยท  4Comments

eraporsmk picture eraporsmk  ยท  5Comments

ahishamali10 picture ahishamali10  ยท  5Comments

Basili0 picture Basili0  ยท  5Comments

jlcanizales picture jlcanizales  ยท  3Comments