php - Laravel Blade: extend multiple views and adding more content -
i have following scenario: view shows data (let's call "cars"), view shows other data (let's call "motorbikes") , view must show data of "cars" , "motorbikes" in addition of content (let's call "vehicles"). the 3 views have sense , can shown separatelly.
the problem can't find way build "vehicles" view without repeating code because don't know how use laravel's blade templating in order extend multiple views ('cars' , 'motorbikes') , add more content. each view divided 3 sections ('styles', 'scripts' , 'content') because html content of each view needs specific css , js files.
layouts/master.blade.php (simplified version)
<html> <head> @yield('styles') @yield('scripts') </head> <body> @yield('content') </body> </html>
cars.blade.php (simplified version)
@extends('layouts.master') @section('styles') [css files required html content shows cars] @stop @section('scripts') [js files required html content shows cars] @stop @section('content') [html content shows cars] @stop
motorbikes.blade.php (simplified version)
@extends('layouts.master') @section('styles') [css files required html content shows motorbikes] @stop @section('scripts') [js files required html content shows motorbikes] @stop @section('content') [html content shows motorbikes] @stop
vehicles.blade.php (simplified version)
@extends('?') <!-- should extend 'cars' , 'motorbikes' --> @section('styles') @parent <!-- should refer content of 'cars' , 'motorbikes' --> [css files required html content shows aditional info vehicles] @stop @section('scripts') @parent <!-- should refer content of 'cars' , 'motorbikes' --> [js files required html content shows aditional info vehicles] @stop @section('content') @parent <!-- should refer content of 'cars' , 'motorbikes' --> [html content shows aditional info vehicles] @stop
undesirable approach
i have thought splitting view 'cars' , view 'motorbikes' separated files like:
cars/styles.blade.php cars/scripts.blade.php cars/content.blade.php motorbikes/styles.blade.php motorbikes/scripts.blade.php motorbikes/content.blade.php
then build vehicles.blade.php this:
@extends('layouts.master') @section('styles') @include('cars.styles') @include('motorbikes.styles') [css files required html content shows aditional info vehicles] @stop @section('scripts') @include('cars.scripts') @include('motorbikes.scripts') [js files required html content shows aditional info vehicles] @stop @section('content') @include('cars.content') @include('motorbikes.content') [html content shows aditional info vehicles] @stop
but want avoid kind of splitting because, in fact, have many more views 'cars' , 'motorbikes' , find undesirable multiply number of files three.
suggestions welcome.
Comments
Post a Comment