Last active
May 2, 2021 13:32
-
-
Save userabuser/7134a6627a2bf8127bdbd56a7759eb2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Blade; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider { | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
/** | |
* Create a custom directive that can be called by @yield('directivename') | |
* | |
* Example: | |
* | |
* In your parent template (parent.blade.php): | |
* | |
* <div>@yield('customdirective')</div> | |
* | |
* In your child blade template (child.blade.php): | |
* | |
* @customdirective('some value) | |
* | |
* Result: | |
* | |
* <div>some value</div> | |
*/ | |
Blade::directive('customdirective', function($expression) { | |
$render = "<?php \$__env->startSection('customdirective'); ?>"; | |
$render .= "<?php echo {$expression}; ?>"; | |
$render .= "<?php \$__env->stopSection(); ?>"; | |
return $render; | |
}); | |
} | |
//etc... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment