Answer the question
In order to leave comments, you need to log in
How to use Blade directive extension in Laravel 5?
Hello. The question arose: how to add custom directives to the Blade template engine in Laravel 5? I write as in the example, but it doesn't work (file "App\Providers\AppServiceProvider.php"):
Blade::directive('date', function($expression) {
return ...;
});
Answer the question
In order to leave comments, you need to log in
Issue resolved. The problem was, firstly, in the Laravel version - as far as I understood, the "directive" method is available only from version 5.1 - the update helped. And, secondly, in cached files on the server. Clearing the cache (not to be confused with clearing the browser cache) solved that part of the problem.
What does "doesn't work" mean? Does it output nothing, outputs the wrong thing, or throws an exception?
Took an example from the Laravel docs:
public function boot()
{
Blade::directive('example', function ($expression) {
return "{$expression}";
});
}
{{ $page_title }} @example('toster.ru') - didn't understand what it was about???
Registration ('toster.ru') - why?
The template is expanded somehow not very clear, or rather not as we would like (((
For example @example('toster.ru') -> returns an object registered under the pseudo name toster.ru - this is a real feature!!! not necessarily toster.ru , you can also @role('content_for_user')...
@example('toster.ru') turns out that what is in brackets does not carry any load. Only example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question