Created
June 24, 2015 23:52
-
-
Save srph/d30e2a629b8c549b402b to your computer and use it in GitHub Desktop.
Blade - Using another directive in a custom directive
This file contains 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 | |
namespace App\Providers; | |
use Blade; | |
use Illuminate\Support\ServiceProvider; | |
use App\Repositories\StoreRepositoryInterface; | |
class BladeServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot(StoreRepositoryInterface $store) | |
{ | |
// $theme = $store->get()['theme']; | |
$theme = theme_path('_blank', 'pages/base'); | |
/** | |
* An abstraction over `extends`. Why? | |
* Without this, you get to type this: | |
* @extends(theme_path($store->theme, 'pages/base')) | |
* Which is so DRY. /s | |
* With this directive, you only get to type this: | |
* @base | |
* | |
* Awesome! | |
* | |
* Not just that, we also get to change some things | |
* only at one place; no need to ctrl + f all files | |
* and change it because we had to change something. | |
* Not only disruptive, but bad programming as well. | |
* | |
* @usage | |
* | |
* @section('my-body') | |
* // other more sections | |
* @base | |
* | |
* Why? Currently Blade does not support custom footers. | |
* Thus, @base is simply a blade directive. | |
*/ | |
Blade::directive('base', function() use ($theme) { | |
// We can't use Blade directives inside a Blade directive, | |
// so we're doing some copy-paste from the `extends` directive. | |
return "<?php echo \$__env->make('{$theme}', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; | |
}); | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment