jeudi 2 janvier 2020

Child partial not injecting styles into its parent blade layout

I have one partial child view that requires some custom js and styles. This child is the only view in the entire application that uses it. It's complex and so the JS was broken off into its own file.

I have tried to 'inject' the script and style into the parent layout according to the docs and it doesn't seem to be working. I have tired a combination of @parent and @@parent in the sections. I have tried changing the main layouts, @yield('scripts') @yield('styles') to @section('scripts')@show.

What am I missing? Is this even possible?

main.blade.php (Shortened For Brevity)

<head>
    @include('apps.includes.styles')

    @yield('styles')//a place for custom style
</head>
<body>
@yield('content')

@include('apps.includes.scripts')
@yield('scripts') //a place for custom scripts
</body>

create.blade.php

@extends('layouts.main')
@section('styles')@endsection
@section('scripts')@endsection
@section('content')
    <div>
      @include('partials._toolbar')
    </div>
@endsection

_toolbar.blade.php

@section('styles')
    @parent
    <script src=""></script>
@endsection

@section('scripts')
    @parent
    <script src=""></script>
@endsection

<section>
// my toolbar html code
</section>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire