Laravel Blade: расширить несколько просмотров и добавить больше контента

У меня есть следующий сценарий: представление, которое показывает некоторые данные (давайте назовем это «автомобили»), другое представление, которое показывает некоторые другие данные (давайте назовем это «мотоциклы») и представление, которое должно отображать данные «автомобили» и « мотоциклы «в дополнение к некоторому дополнительному контенту (назовем это» транспортными средствами «). Три представления имеют смысл сами по себе и могут быть показаны отдельно.

Проблема в том, что я не могу найти способ построить вид «транспортных средств» без повторения кода потому что я не знаю, как использовать лезвие Laravel’s Templating для того, чтобы расширить несколько просмотров («автомобили» и «мотоциклы») и добавить больше контента. Каждое представление разделено на три раздела («стили», «сценарии» и «содержимое»), поскольку для содержимого HTML каждого представления требуются определенные файлы CSS и JS.

layouts / master.blade.php (упрощенная версия)

<html>
<head>
@yield('styles')
@yield('scripts')
</head>
<body>
@yield('content')
</body>
</html>

cars.blade.php (упрощенная версия)

@extends('layouts.master')

@section('styles')
[CSS files required by the HTML content that shows cars]
@stop
@section('scripts')
[JS files required by the HTML content that shows cars]
@stop
@section('content')
[HTML content that shows cars]
@stop

motorbikes.blade.php (упрощенная версия)

@extends('layouts.master')

@section('styles')
[CSS files required by the HTML content that shows motorbikes]
@stop
@section('scripts')
[JS files required by the HTML content that shows motorbikes]
@stop
@section('content')
[HTML content that shows motorbikes]
@stop

vehicle.blade.php (упрощенная версия)

@extends('?') <!-- It should extend 'cars' and 'motorbikes' -->

@section('styles')
@parent <!-- It should refer to the content of 'cars' and 'motorbikes' -->
[CSS files required by the HTML content that shows aditional info about vehicles]
@stop
@section('scripts')
@parent <!-- It should refer to the content of 'cars' and 'motorbikes' -->
[JS files required by the HTML content that shows aditional info about vehicles]
@stop
@section('content')
@parent <!-- It should refer to the content of 'cars' and 'motorbikes' -->
[HTML content that shows aditional info about vehicles]
@stop

Нежелательный подход

Я уже думал о разделении представления «автомобили» и представления «мотоциклы» на отдельные файлы, такие как:

cars/styles.blade.php
cars/scripts.blade.php
cars/content.blade.php
motorbikes/styles.blade.php
motorbikes/scripts.blade.php
motorbikes/content.blade.php

Тогда я мог бы собрать Vehicles.blade.php, как это:

@extends('layouts.master')

@section('styles')
@include('cars.styles')
@include('motorbikes.styles')
[CSS files required by the HTML content that shows aditional info about vehicles]
@stop
@section('scripts')
@include('cars.scripts')
@include('motorbikes.scripts')
[JS files required by the HTML content that shows aditional info about vehicles]
@stop
@section('content')
@include('cars.content')
@include('motorbikes.content')
[HTML content that shows aditional info about vehicles]
@stop

Но я хочу избежать такого разделения, потому что на самом деле у меня гораздо больше просмотров, чем просто «автомобили» и «мотоциклы», и я считаю нежелательным умножать количество файлов на три.

Предложения приветствуются.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector