andris-briedis's avatar

How to expand the template at various levels?

Hello.

I have a basic template: the "master". It will include many files with tables extends to (). Not one time. Clicking on the "url". In all of these table files pagination is the same. Just different to the transferred numbers. Therefore pagination I want a separate file. Just can not figure out how it can be done with extends, sections and yield. Is it possible at all? Or be used include()?

Links are pictures that it all better description.

https://www.dropbox.com/s/8uzyvade5aeliys/Laravel-extends.png?dl=0

0 likes
3 replies
zachleigh's avatar

Im not 100% sure about your situation, but what I usually do is this. I have one master template that looks something like this:

<!DOCTYPE html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
        <meta name="language" content="English"> 

        @yield('meta')

        <title>
            @yield('title')
        </title>

        @yield('style')
    </head>

    <body>
        <div class="wrapper">
            <header>
                @include ('header')
            </header>

            <div id="content">
                @yield('content')
            </div>
        </div>
        
            <div id="footer">
                @include ('footer')
            </div>
            
        @yield ('scripts')
        
    </body>
</html>

I then have sub pages that look something like this:

@extends('master')

@section('title')
    Title
@stop

@section('content')
    <div>
        Content

        @include ('pages.some_page')

        Content
        
        @include (pages.another_page')
        
        Content
    </div>
@stop

@section('scripts')
    <script type="text/javascript" src="/output/page.js"></script>
@stop

Everything that is similar between pages is in the sub page template and then the different parts are included with @include.

andris-briedis's avatar

Thank you. Conceptually, it is clear that should be taken include (). And extends () hack there is no reasonable trouble.

bobbybouwmann's avatar

Well you can do something like this

// resources/views/partials/pagination.php
<div class="my-pagination">
    
    {!! $resource->render() !!}

</div>

Then you can do something like this on all your pages

@extends('master')

@section('content')

    <table>
        @foreach($users as $user)

            // Display content of users         

        @endforeach
    </table>

    @include('partials.pagination', ['resource' => $users])

@stop

Now you only have one place to update the pagination ;)

Please or to participate in this conversation.