Skip to content

Instantly share code, notes, and snippets.

@mrkmg
Last active August 29, 2015 14:10
Show Gist options
  • Save mrkmg/ddc183f3ce881d9fb636 to your computer and use it in GitHub Desktop.
Save mrkmg/ddc183f3ce881d9fb636 to your computer and use it in GitHub Desktop.
Adds @asset, @assetjs, @assetcss to blade templates
<?php
// Adds @asset tag to blade templates;
// USAGE: @asset('path/to/file.css|js')
Blade::extend(function($view, \Illuminate\View\Compilers\BladeCompiler $compiler)
{
$pattern = $compiler->createMatcher('asset');
return preg_replace($pattern, '<?php Assets::add$2; ?>', $view);
});
// Adds @assetjs tag to blade templates;
// USAGE: @assetjs('path/to/file.js')
Blade::extend(function($view, \Illuminate\View\Compilers\BladeCompiler $compiler)
{
$pattern = $compiler->createMatcher('assetjs');
return preg_replace($pattern, '<?php Assets::addJs$2; ?>', $view);
});
// Adds @assetcss tag to blade templates;
// USAGE: @assetcss('path/to/file.css')
Blade::extend(function($view, \Illuminate\View\Compilers\BladeCompiler $compiler)
{
$pattern = $compiler->createMatcher('assetcss');
return preg_replace($pattern, '<?php Assets::addCss$2; ?>', $view);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment