Looking to hire Laravel developers? Try LaraJobs
This package is not available.

laravel-blade-include-relative maintained by fukumori

Description
Allows to include blade template with relative path based on current view.
Author
Last update
2019/08/28 22:28 (dev-master)
License
Links
Downloads
9 494

Comments
comments powered by Disqus

Laravel Blade Include Relative

Allows to include blade template with relative path based on current view.

Installation

Require this package with composer.

composer require fukumori/laravel-blade-include-relative

Clear view cache BEFORE usage

php artisan view:clear

Usage

Make your view including sub-view with relative path

<!-- Stored in resources/views/site/some-file.blade.php -->

{{-- full include with hint --}}
@include('site::partials.included-view', ['name' => 'site::partials.included-view'])
{{-- full include (normal usage) --}}
@include('site.partials.included-view', ['name' => 'site.partials.included-view'])
{{-- relative include --}}
@include('partials.included-view', ['name' => 'partials.included-view'])
{{-- relative includeIf --}}
@includeIf('partials.included-view', ['name' => 'if partials.included-view'])
{{-- relative includeWhen --}}
@includeWhen(true, 'partials.included-view', ['name' => 'when partials.included-view'])
{{-- relative each --}}
@each('partials.included-view', ['each1 partials.included-view', 'each2 partials.included-view'], 'name')

Make your sub-view

<!-- Stored in resources/views/site/partials/included-view.blade.php -->

<div>Included view with: {{ $name ?? '' }}.</div>

Call your view

<!-- Stored in routes/web.php -->

Route::view('/test', 'site.some-file');

See the magic appear

<div>Included view with: site::partials.included-view.</div>
<div>Included view with: site.partials.included-view.</div>
<div>Included view with: partials.included-view.</div>
<div>Included view with: if partials.included-view.</div>
<div>Included view with: when partials.included-view.</div>
<div>Included view with: each1 partials.included-view.</div>
<div>Included view with: each2 partials.included-view.</div>

Know Issues

If a view was previously loaded with a name and does not exist in the current paths, the last valid view with that name will be include.