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

Page Part Bundle Laravel Package

dcouture-ca/page-part-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dcouture-ca/page-part-bundle
    

    Add to config/app.php under providers:

    Dcouture\PagePartBundle\PagePartServiceProvider::class,
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Dcouture\PagePartBundle\PagePartServiceProvider"
    
  2. Basic Usage Register a page part via a service provider or manually:

    use Dcouture\PagePartBundle\Contracts\PagePartInterface;
    
    class MyPagePart implements PagePartInterface {
        public function render(): string {
            return '<div>Hello, Page Part!</div>';
        }
    }
    

    Register it in AppServiceProvider:

    public function boot() {
        $this->app->make('page-part')->register('my_part', MyPagePart::class);
    }
    
  3. First Use Case Render a page part in a Blade view:

    @pagePart('my_part')
    

Implementation Patterns

Core Workflow

  1. Registration

    • Register parts via PagePartServiceProvider or manually in boot().
    • Use tags for dynamic loading (e.g., registerWithTag()).
  2. Rendering

    • Blade directive: @pagePart('slug') (auto-renders if registered).
    • Programmatic rendering:
      $part = app('page-part')->get('my_part');
      echo $part->render();
      
  3. Dynamic Parts

    • Pass data to parts via setData():
      $part->setData(['key' => 'value']);
      
  4. View Integration

    • Extend Blade with custom directives:
      Blade::directive('pagePart', function ($slug) {
          return "<?php echo app('page-part')->render({$slug}); ?>";
      });
      

Advanced Patterns

  • Dependency Injection Inject PagePartManager into controllers/services:

    public function __construct(protected PagePartManager $manager) {}
    
  • Conditional Rendering Use has() to check part existence:

    if ($manager->has('my_part')) {
        echo $manager->render('my_part');
    }
    
  • Caching Cache rendered parts globally or per-request:

    $manager->setCacheEnabled(true);
    

Gotchas and Tips

Common Pitfalls

  1. Registration Timing

    • Parts must be registered before first use (e.g., in boot()).
    • Avoid lazy registration in routes/middleware.
  2. Namespace Collisions

    • Ensure part class names are unique (e.g., App\PageParts\MyPart).
  3. Blade Directive Scope

    • @pagePart only works in Blade files. Use $manager->render() elsewhere.
  4. Data Binding

    • setData() overwrites existing data. Use mergeData() for partial updates.

Debugging Tips

  • Check Registration Dump registered parts:

    dd(app('page-part')->getRegisteredParts());
    
  • Enable Debug Mode Set debug: true in config to log missing parts.

  • Override Rendering Extend PagePartManager to customize behavior:

    class CustomManager extends PagePartManager {
        public function render($slug) {
            // Custom logic
            return parent::render($slug);
        }
    }
    

Extension Points

  1. Custom Storage Override getStorage() to use a database or API:

    $manager->setStorage(new CustomStorage());
    
  2. Event Hooks Listen for PagePartRendering events to modify output:

    event(new PagePartRendering($part, $slug));
    
  3. View Composers Bind parts to views:

    View::composer('*', function ($view) {
        $view->with('parts', app('page-part')->getAll());
    });
    
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours