Skip to content

Instantly share code, notes, and snippets.

@JSila
Last active August 29, 2015 14:16
Show Gist options
  • Save JSila/e05f268e1b5ffad42e50 to your computer and use it in GitHub Desktop.
Save JSila/e05f268e1b5ffad42e50 to your computer and use it in GitHub Desktop.
Few additional tags for blade templating engine
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class BladeExtensionsProvider extends ServiceProvider {
// Don't forget to register this provider in config/app.php
//
// Or if you don't want to bother, add content of boot function
// to AppServiceProvider.php's boot function
public function boot()
{
\Blade::extend(function($view, $compiler) {
$tagTypes = [
'Form' => [
'open', 'close', 'label', 'text', 'textarea', 'select',
'url', 'submit', 'token', 'input', 'password', 'email',
'file', 'selectRange', 'selectYear', 'selectMonth', 'opion',
'optionGroup', 'checkbox', 'radio', 'chackable', 'reset',
'button', 'hidden'
],
'Html' => [
'entities', 'decode', 'script', 'style', 'image', 'link',
'secureLink', 'linkAsset', 'linkSecureAsset', 'linkRoute',
'linkAction', 'mailto', 'ol', 'ul', 'listing'
]
];
foreach ($tagTypes as $tagType => $tags) {
foreach ($tags as $tag) {
$view = preg_replace(
$compiler->createMatcher($tag),
'$1<?php echo '.$tagType.'::' . $tag . '$2; ?>',
$view
);
}
}
$view = preg_replace(
$compiler->createOpenMatcher('diffForHumans'),
'$1<?php echo $2->diffForHumans()); ?>',
$view
);
$view = preg_replace(
$compiler->createPlainMatcher('open'),
'$1<?php echo Form::open() ?>',
$view
);
$view = preg_replace(
$compiler->createPlainMatcher('close'),
'$1<?php echo Form::close() ?>',
$view
);
return $view;
});
}
public function register()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment