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)
)
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.
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.
##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.
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})");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With