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 Bundle Laravel Package

eight/page-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install Dependencies Run:

    composer require eight/page-bundle sonata-project/admin-bundle raindrop/routing-bundle
    

    Ensure fos/user-bundle is installed if using user authentication.

  2. Configure Bundles Add to config/bundles.php:

    Eight\PageBundle\EightPageBundle::class => ['all' => true],
    Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
    RainDrop\RoutingBundle\RainDropRoutingBundle::class => ['all' => true],
    
  3. Enable Dynamic Routing Update config/routes.yaml:

    raindrop_routing:
        resource: "@EightPageBundle/Resources/config/routing.yml"
        prefix: /
    
  4. First Page Creation Run migrations (if applicable) and create a page via Sonata Admin:

    php bin/console doctrine:migrations:migrate
    

    Navigate to /admin/page to add a new page.

  5. Render a Page in Twig Use the eight_page Twig function:

    {{ eight_page('home') }}
    

Implementation Patterns

Core Workflow

  1. Page Structure

    • Define pages in Sonata Admin (/admin/page).
    • Use blocks (e.g., text, image, widget) for modular content.
    • Example block configuration in YAML:
      blocks:
          - { type: 'text', content: 'Hello, world!' }
          - { type: 'image', src: '/uploads/image.jpg' }
      
  2. Dynamic Routing

    • Pages auto-route via RainDropRoutingBundle.
    • Override routes in config/routes.yaml:
      eight_page_home:
          path: /home
          defaults: { _controller: eight_page.controller:pageAction, page: 'home' }
      
  3. Twig Integration

    • Render a page:
      {% set page = eight_page('about') %}
      <h1>{{ page.title }}</h1>
      {{ page.render() }} {# Renders all blocks #}
      
    • Render a specific block:
      {{ page.blocks[0].render() }}
      
  4. Programmatic Page Editing

    • Load/export pages via YAML:
      $loader = $container->get('eight_page.loader.yml');
      $pages = $loader->load('path/to/pages.yml');
      $loader->export($pages, 'path/to/export.yml');
      
  5. Widget Integration

    • Extend with custom widgets by implementing Eight\PageBundle\Model\WidgetInterface.
    • Register in services.yaml:
      services:
          App\Widget\CustomWidget:
              tags: [eight_page.widget]
      

Gotchas and Tips

Pitfalls

  1. Bootstrap Version Mismatch

    • Ensure 1.0.x uses Bootstrap 3.x and 1.3.x uses Bootstrap 4.x.
    • Conflict risk: If using Bootstrap 5, manually override CSS/JS assets.
  2. Routing Conflicts

    • RainDropRoutingBundle may clash with static routes.
    • Fix: Explicitly define page routes in config/routes.yaml or use priorities:
      raindrop_routing:
          priority: -10  # Lower priority than static routes
      
  3. Sonata Admin Dependency

    • Requires Sonata Admin for the backend.
    • Workaround: Use a custom admin class if migrating away from Sonata.
  4. YAML Loader Quirks

    • Indentation must be spaces (not tabs) in YAML files.
    • Debug tip: Validate YAML with symfony/validator:
      use Symfony\Component\Yaml\Yaml;
      $pages = Yaml::parseFile('pages.yml');
      
  5. Caching Issues

    • Clear cache after page updates:
      php bin/console cache:clear
      
    • Pro tip: Use eight_page.cache_lifetime in config to disable caching for testing.

Debugging Tips

  1. Check Page Existence

    • Verify pages exist in the database:
      php bin/console doctrine:query:sql "SELECT * FROM eight_page"
      
  2. Widget Debugging

    • Enable debug mode for widgets:
      # config/packages/eight_page.yaml
      eight_page:
          debug_widgets: true
      
    • Log widget errors in var/log/dev.log.
  3. Twig Errors

    • Wrap eight_page calls in try-catch:
      {% try %}
          {{ eight_page('nonexistent') }}
      {% catch %}
          <p>Page not found.</p>
      {% endtry %}
      

Extension Points

  1. Custom Block Types

    • Extend Eight\PageBundle\Model\BlockInterface for reusable blocks.
    • Example:
      class CustomBlock extends AbstractBlock
      {
          public function render(): string
          {
              return $this->renderView('blocks/custom.html.twig', ['content' => $this->content]);
          }
      }
      
  2. Override Admin Templates

    • Copy templates from EightPageBundle/Resources/views to templates/bundles/eightpage.
    • Example: Override page_edit.html.twig.
  3. Event Listeners

    • Hook into page events (e.g., eight_page.pre_save):
      // src/EventListener/PageListener.php
      class PageListener
      {
          public function onPreSave(PageEvent $event)
          {
              $page = $event->getPage();
              $page->setMetaDescription('Default meta description');
          }
      }
      
      Register in services.yaml:
      services:
          App\EventListener\PageListener:
              tags: [kernel.event_listener, name: eight_page.pre_save]
      
  4. Storage Backend

    • Switch storage (e.g., database → filesystem) by implementing Eight\PageBundle\Storage\StorageInterface.
    • Configure in config/packages/eight_page.yaml:
      eight_page:
          storage: App\Storage\CustomStorage
      
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware