Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Layouttag Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require abo/layouttag
    

    Publish the config file (if needed):

    php artisan vendor:publish --provider="Abo\LayoutTag\LayoutTagServiceProvider"
    
  2. Basic Usage The package is designed to work with layoutit (a backend extension for Vue/React admin panels). To use it standalone:

    • Register the service provider in config/app.php:
      'providers' => [
          Abo\LayoutTag\LayoutTagServiceProvider::class,
      ],
      
    • Use the LayoutTag facade or resolve the service:
      use Abo\LayoutTag\Facades\LayoutTag;
      
      $tag = LayoutTag::make('my_tag')->setContent('Hello, Layout!');
      echo $tag->render();
      
  3. 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')
    

Implementation Patterns

Workflow: Tag Management

  1. Creating Tags

    // Basic tag
    $tag = LayoutTag::make('header')->setContent('<h1>Welcome</h1>');
    
    // With attributes (e.g., for conditional rendering)
    $tag->setAttributes(['class' => 'dynamic-header']);
    
  2. Tag Storage & Retrieval

    • Session Storage (default):
      LayoutTag::store('sidebar', view('components.sidebar'));
      echo LayoutTag::get('sidebar');
      
    • Database Storage (if extended):
      // Requires custom implementation (see "Extension Points")
      LayoutTag::db()->store('footer', $content);
      
  3. Integration with Layoutit If using layoutit, tags are auto-rendered in the admin panel. Configure via:

    LayoutTag::config(['layoutit' => true]);
    

Common Patterns

  • Conditional Tags:
    if (auth()->check()) {
        LayoutTag::make('user-panel')->setContent(view('user.dashboard'));
    }
    
  • Reusable Components:
    LayoutTag::make('analytics')->setContent(
        LayoutTag::component('AnalyticsChart', ['data' => $stats])
    );
    
  • AJAX Updates:
    // Fetch and update a tag via JS
    fetch('/update-tag?tag=notifications')
        .then(response => response.text())
        .then(html => document.getElementById('notifications').innerHTML = html);
    

Gotchas and Tips

Pitfalls

  1. Namespace Collisions

    • If using 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}); ?>";
      });
      
  2. Session Dependency

    • Tags stored in the session are not persistent across requests. For persistence:
      • Use a database (extend the package).
      • Cache tags with Cache::put().
  3. Layoutit-Specific Quirks

    • If layoutit is not configured, tags may render as plain HTML. Verify:
      if (!LayoutTag::config('layoutit')) {
          // Fallback to manual rendering
      }
      

Debugging Tips

  • Check Stored Tags:
    dd(LayoutTag::all()); // List all stored tags
    
  • Clear Cached Tags:
    LayoutTag::flush(); // Clears session storage
    
  • Log Tag Rendering: Enable debug mode in config:
    'debug' => env('LAYOUT_TAG_DEBUG', false),
    

Extension Points

  1. 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);
    
  2. Tag Events Listen for tag creation/rendering:

    LayoutTag::listen('rendering', function ($tag) {
        // Log or modify tag before rendering
    });
    
  3. Blade Directives Extend the @layoutTag directive:

    Blade::directive('layoutTag', function ($expression) {
        return "<?php echo \\Custom\\TagRenderer::render({$expression}); ?>";
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
croct/coding-standard
croct/plug-php
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields