Skip to content

Commit

Permalink
Merge pull request #21 from alexjoffroy/feature/add-blade-directives
Browse files Browse the repository at this point in the history
Add `@meta` and `@metas` directives
  • Loading branch information
eusonlito authored Aug 9, 2018
2 parents 4ceeb6b + e0d2b4f commit a436367
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,42 @@ class HomeController extends Controller
</html>
```

Or you can use Blade directives:

```php
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Lito - [email protected]" />

<title>{!! Meta::get('title') !!}</title>

@meta('robots')

@meta('site_name', 'My site')
@meta('url', Request::url())
@meta('locale', 'en_EN')

@meta('title')
@meta('description')

{{-- Print custom section images and a default image after that --}}
@meta('image', asset('images/default-logo.png'))

{{-- Or use @metas to get all tags at once --}}
@metas

</head>

<body>
...
</body>
</html>
```

### Config

```php
Expand Down
21 changes: 21 additions & 0 deletions src/Eusonlito/LaravelMeta/MetaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Eusonlito\LaravelMeta;

use Illuminate\Support\ServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;

class MetaServiceProvider extends ServiceProvider
{
Expand All @@ -22,6 +23,8 @@ public function boot()
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('meta.php')
]);

$this->addBladeDirectives();
}

/**
Expand All @@ -45,4 +48,22 @@ public function provides()
{
return ['meta'];
}

/**
* Register blade directives
*
* @return void
*/
protected function addBladeDirectives()
{
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
$bladeCompiler->directive('meta', function ($arguments) {
return "<?php echo Meta::tag($arguments); ?>";
});

$bladeCompiler->directive('metas', function ($arguments) {
return "<?php echo Meta::tags($arguments); ?>";
});
});
}
}

0 comments on commit a436367

Please sign in to comment.