Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

fukumori/laravel-blade-include-relative

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages