Weave 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

Pagebundle Laravel Package

cekurte/pagebundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require cekurte/pagebundle
    

    Add the bundle to config/bundles.php (Symfony) or config/app.php (Laravel via bridge):

    // Laravel (if using a Symfony bridge)
    Cekurte\PageBundle\CekurtePageBundle::class => ['all' => true],
    
  2. Publish Assets & Config

    php artisan vendor:publish --provider="Cekurte\PageBundle\CekurtePageBundle" --tag="config"
    php artisan vendor:publish --provider="Cekurte\PageBundle\CekurtePageBundle" --tag="public"
    
  3. First Use Case: Create a Page

    • Run migrations:
      php artisan migrate
      
    • Register a new page via the admin interface (if available) or manually via Tinker:
      use Cekurte\PageBundle\Entity\Page;
      $page = new Page();
      $page->setTitle('About Us');
      $page->setSlug('about');
      $page->setContent('<h1>Welcome to our page!</h1>');
      $page->setTemplate('default.html.twig'); // or custom template
      $page->setPublished(true);
      $page->setWidgets([/* widget config */]);
      $em->persist($page);
      $em->flush();
      
  4. Display a Page In a controller or Twig template:

    {{ render_page('about') }}
    

    Or in Laravel (if using a bridge):

    return view('page', ['page' => \Cekurte\PageBundle\PageManager::getPage('about')]);
    

Implementation Patterns

Core Workflows

  1. Page Management

    • CRUD via Admin: Use the provided admin interface (if enabled) to manage pages, widgets, and templates.
    • Programmatic Creation: Create pages dynamically in controllers or services:
      $pageManager = $this->get('cekurte_page.manager');
      $page = $pageManager->createPage([
          'title' => 'Contact',
          'slug' => 'contact',
          'content' => '<p>Reach out to us!</p>',
          'widgets' => [
              ['type' => 'contact_form', 'config' => [...]]
          ]
      ]);
      
  2. Widget Integration

    • Built-in Widgets:
      • Google Maps: Configure via google_maps widget type with api_key, lat, lng, and zoom.
      • Contact Form: Use contact_form widget type with recipient_email and fields.
    • Custom Widgets: Extend the bundle by creating a new widget class and registering it in the service container:
      # config/services.yaml (Symfony) or config/app.php (Laravel)
      services:
          App\Widget\CustomWidget:
              tags:
                  - { name: cekurte_page.widget, type: custom_widget }
      
  3. Template Overrides

    • Override default templates by copying files from: vendor/cekurte/pagebundle/Resources/views/ to resources/views/cekurte_page/.
    • Customize page rendering logic by extending the PageRenderer service.
  4. Routing

    • Pages are automatically routed via slug. Example:
      /about → Renders the 'about' page.
      
    • Override routing by defining custom routes in routes/web.php:
      Route::get('/custom-page', 'PageController@show')->name('page.custom');
      
  5. Localization

    • Translate page titles/content using Symfony’s translation system or Laravel’s localization:
      {{ page.title|trans }}
      

Integration Tips

  • Laravel-Specific:
    • Use the PageBundle bridge (if available) to integrate with Laravel’s service container and Blade templates.
    • Example Blade template:
      @component('cekurte-page::page', ['page' => $page])
      @endcomponent
      
  • Symfony-Specific:
    • Leverage Twig’s render_page function for dynamic page rendering.
    • Use dependency injection for the PageManager service:
      public function __construct(\Cekurte\PageBundle\Manager\PageManager $pageManager) {
          $this->pageManager = $pageManager;
      }
      
  • Frontend Integration:
    • Load widget-specific assets (e.g., Google Maps API) via Twig:
      {% block javascripts %}
          {{ parent() }}
          {{ widget_javascripts(page.widgets) }}
      {% endblock %}
      

Gotchas and Tips

Pitfalls

  1. Widget Configuration:

    • Missing Widget Types: Only google_maps and contact_form are built-in. Custom widgets require manual registration.
    • Validation Errors: Widget configs must match expected schema. Validate in Tinker before deployment:
      $widget = ['type' => 'google_maps', 'config' => ['api_key' => 'invalid']];
      $pageManager->validateWidget($widget); // Throws exception if invalid.
      
  2. Routing Conflicts:

    • Pages with slugs like admin or login may conflict with Laravel/Symfony’s default routes. Exclude them via:
      $page->setExcludedFromRouting(true);
      
  3. Template Inheritance:

    • Overriding templates requires copying the entire template hierarchy. Use extends in custom templates:
      {% extends 'cekurte_page::base.html.twig' %}
      
  4. Database Migrations:

    • Customize the Page entity by extending it and updating migrations:
      // src/Entity/ExtendedPage.php
      use Cekurte\PageBundle\Entity\Page as BasePage;
      
      class ExtendedPage extends BasePage {
          // Add custom fields.
      }
      
    • Update the bundle’s migration files or create a new migration.
  5. Caching:

    • Pages are cached by default. Clear cache after updates:
      php artisan cache:clear
      
    • Disable caching for development:
      $pageManager->setCacheEnabled(false);
      

Debugging

  1. Widget Rendering Issues:

    • Check widget logs in storage/logs/laravel.log (Laravel) or var/log/dev.log (Symfony).
    • Enable debug mode for Twig:
      // config/packages/twig.yaml (Symfony)
      twig:
          debug: true
      
  2. Route Debugging:

    • Dump routes to identify conflicts:
      php artisan route:list
      
    • Test page rendering in Tinker:
      $page = $pageManager->getPage('about');
      var_dump($page->getWidgets());
      
  3. Database Issues:

    • Verify migrations ran:
      php artisan migrate:status
      
    • Check the pages and widgets tables for expected data.

Tips

  1. Development Workflow:

    • Use the dev environment to test widgets and templates without caching:
      // config/app.php (Laravel)
      'env' => env('DEV', 'local'),
      
    • Enable Twig debugging for real-time template updates.
  2. Performance:

    • Lazy-load widgets in templates:
      {% for widget in page.widgets if widget.type == 'google_maps' %}
          {{ render_widget(widget) }}
      {% endfor %}
      
    • Use fragment caching for static page content:
      {% cache 'page_about_content' %}
          {{ page.content }}
      {% endcache %}
      
  3. Extending Functionality:

    • Custom Widget Events: Dispatch events for widget rendering:
      // In a service
      $event = new WidgetRenderEvent($widget);
      $this->eventDispatcher->dispatch($event, WidgetEvents::PRE_RENDER);
      
    • Page Events: Listen for page.save or page.delete events to trigger actions.
  4. Testing:

    • Test page rendering with PHPUnit:
      public function testPageRendering() {
          $page = $this->createMock(Page::class);
          $page->method('getSlug')->willReturn('test');
          $this->assertEquals('Test Page', $this->pageManager->getPage('test')->getTitle());
      }
      
    • Use Laravel’s HTTP tests for route testing:
      $response = $this->get('/test');
      $response->assertSee('Test Content');
      
  5. Localization:

    • Translate widget labels and placeholders:
      # config/translation_messages.yaml (Symfony)
      en:
          cekurte_page:
              widgets:
                  google_maps:
                      title: 'Map Location'
      
    • In Laravel
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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log