#Which is a best practice approach, Blade Template inheritance and Blade components?
1 messages · Page 1 of 1 (latest)
There’s no “best practice”. They’re just two ways to accomplish the same thing. So pick which ever one you prefer 🙂
@rigid palm Thank you!
I guess what I was thinking was that there were underline functionality between the two...
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