#Which is a best practice approach, Blade Template inheritance and Blade components?

1 messages · Page 1 of 1 (latest)

dense narwhal
#

Hello Everyone,
I'm a little confused on which approach is best, currently I am working on a blog, and I am not sure what approach to take…? I was wondering if anyone knows of a good article that gives good scenarios or if we anyone could list a few examples here. TIA

rigid palm
dense narwhal
#

@rigid palm Thank you!

#

I guess what I was thinking was that there were underline functionality between the two...

rigid palm
#

It’s just syntax, really. There’s “inheritance” based layouts that look like this:

@extends('layout')

@section('title', 'Page Title')

@section('content')
    <!-- Mark up for main content of page here -->
@endsection

And then there are component-based layouts that look more “HTML-y” like this:

<x-layout title="Page Title">
    <!-- Mark up for main content of page here -->
</x-layout>
#

I prefer the first version, because you can do things like define “stacks” for things like meta tags, preload links, that you can then “push” to on a per-page basis.

#

For example, I have a video on demand platform so I push the JavaScript I need for the video player on video pages only:

<!-- resources/views/videos/show.blade.php -->
@extends('layout')

@push('scripts')
    <script defer src="{{ mix('js/video-player.js') }}"></script>
@endpush

@push('content')
    <!-- Video page content here -->
@endpush