P
P
photosho2016-01-29 12:26:39
Laravel
photosho, 2016-01-29 12:26:39

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 ...;
});

Perhaps this example was created for other versions of Laravel?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
photosho, 2016-01-30
@photosho

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.

D
Dmitry, 2016-01-29
@Astatroth

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}";
        });
    }

In the template:
As a result, I got:
Everything works.

A
Andrey Shakhtarin, 2017-03-12
@AndereyKross

{{ $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 question

Ask a Question

731 491 924 answers to any question