abo/layouttag
Laravel package to manage and render layout tags in your views/components. Define reusable tag definitions, parse and transform tagged content, and integrate into Blade for cleaner templates and consistent layout markup across your app.
Installation
composer require abo/layouttag
Publish the config file (if needed):
php artisan vendor:publish --provider="Abo\LayoutTag\LayoutTagServiceProvider"
Basic Usage The package is designed to work with layoutit (a backend extension for Vue/React admin panels). To use it standalone:
config/app.php:
'providers' => [
Abo\LayoutTag\LayoutTagServiceProvider::class,
],
LayoutTag facade or resolve the service:
use Abo\LayoutTag\Facades\LayoutTag;
$tag = LayoutTag::make('my_tag')->setContent('Hello, Layout!');
echo $tag->render();
First Use Case: Dynamic Layout Injection Inject tags into Blade views dynamically:
LayoutTag::make('sidebar')->setContent(view('partials.sidebar'))->render();
Then, in Blade:
@layoutTag('sidebar')
Creating Tags
// Basic tag
$tag = LayoutTag::make('header')->setContent('<h1>Welcome</h1>');
// With attributes (e.g., for conditional rendering)
$tag->setAttributes(['class' => 'dynamic-header']);
Tag Storage & Retrieval
LayoutTag::store('sidebar', view('components.sidebar'));
echo LayoutTag::get('sidebar');
// Requires custom implementation (see "Extension Points")
LayoutTag::db()->store('footer', $content);
Integration with Layoutit If using layoutit, tags are auto-rendered in the admin panel. Configure via:
LayoutTag::config(['layoutit' => true]);
if (auth()->check()) {
LayoutTag::make('user-panel')->setContent(view('user.dashboard'));
}
LayoutTag::make('analytics')->setContent(
LayoutTag::component('AnalyticsChart', ['data' => $stats])
);
// Fetch and update a tag via JS
fetch('/update-tag?tag=notifications')
.then(response => response.text())
.then(html => document.getElementById('notifications').innerHTML = html);
Namespace Collisions
layoutTag directive in Blade, ensure no other packages override @layoutTag. Check:
Blade::directive('layoutTag', function ($expression) {
return "<?php echo \\Abo\\LayoutTag\\Facades\\LayoutTag::get({$expression}); ?>";
});
Session Dependency
Cache::put().Layoutit-Specific Quirks
layoutit is not configured, tags may render as plain HTML. Verify:
if (!LayoutTag::config('layoutit')) {
// Fallback to manual rendering
}
dd(LayoutTag::all()); // List all stored tags
LayoutTag::flush(); // Clears session storage
'debug' => env('LAYOUT_TAG_DEBUG', false),
Custom Storage Override the default storage (session) by binding a new driver:
LayoutTag::extend('database', function ($app) {
return new DatabaseTagStore($app['db']);
});
Then use:
LayoutTag::driver('database')->store('tag', $content);
Tag Events Listen for tag creation/rendering:
LayoutTag::listen('rendering', function ($tag) {
// Log or modify tag before rendering
});
Blade Directives
Extend the @layoutTag directive:
Blade::directive('layoutTag', function ($expression) {
return "<?php echo \\Custom\\TagRenderer::render({$expression}); ?>";
});
How can I help you explore Laravel packages today?