Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a Blade directive in a Blade directive

I'm using Laravel 5.1. I am trying to use a Blade directive (@extend) with my custom Blade directive.

Blade::directive('base', function() use ($theme) {
  return "@extends($theme)"
});

However, the above code only literally displays the contents (@extends($theme))

like image 309
srph Avatar asked Jun 21 '15 19:06

srph


People also ask

What is Blade directive?

Blade directives are shortcut codes for the implementation of basic PHP structure control, such as loop and conditional statements. It makes your code snippets clean and easy to understand. Note: These directives are basically only used in the blade template, so don't try to use them on your controllers.

Which is the correct looping syntax in term of blade engine?

The blade templating engine provides loops such as @for, @endfor, @foreach, @endforeach, @while, and @endwhile directives. These directives are used to create the php loop equivalent statements.

What is the use of @CAN in Laravel?

##Permissions This package doesn't add any permission-specific Blade directives. Instead, use Laravel's native @can directive to check if a user has a certain permission. You can use @can , @cannot , @canany , and @guest to test for permission-related access.


1 Answers

Contrary to a comment I made earlier, I think this is possible (but untested) using the blade compiler.

Blade::directive('base', function() use ($theme) {
    return Blade::compileString("@extends({$theme})");
});
like image 198
David Barker Avatar answered Nov 15 '22 03:11

David Barker