Reputation: 229
Good day,
Here is my directory structure for blades.
resources/views/red/main.blade.php
resources/views/red/include_me.blade.php
resources/views/blue/main.blade.php
resources/views/blue/include_me.blade.php
This is the include in the red main.blade.php...
@include('red.include_me')
This is the include in the blue main.blade.php...
@include('blue.include_me')
Is there a way to include it so I no longer have to specify red or blue?
@include('include_me')
Upvotes: 1
Views: 297
Reputation: 8618
You can use this
@php $part = (condition) ? 'red' : 'blue'; @endphp
@include($part . '.include_me')
Upvotes: 2
Reputation: 3898
Nope that is not possible. How should Laravel / Blade distinguish between them? blue
and red
act as a namespace here. You also can not have two files with same name in same folder.
Upvotes: 3