Reputation: 3664
I want to extend blade in laravel 4 to have some custom commands and I want to call them without brackets. For example I want to call:
@test
So I've created Blade::extend function like so:
Blade::extend(function($view, $compiler)
{
$pattern = $compiler->createMatcher('test');
return preg_replace($pattern, '$1<?php echo "test"; ?>', $view);
});
It works fine when I call it with:
@test()
But fails when I call it with just:
@test
How can I achieve this?
Upvotes: 1
Views: 407
Reputation: 3664
The thing was with preg_replace pattern. Diving into BladeCompiler
I found out that it has more that one createMatcher
method.
To call
@test
without brackets, just change
$pattern = $compiler->createMatcher('test');
to:
$pattern = $compiler->createPlainMatcher('test');
which creates proper pattern in that case.
Upvotes: 2