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

Static Page Content Bundle Laravel Package

c33s/static-page-content-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require c33s/static-page-content-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        C33s\StaticPageContentBundle\C33sStaticPageContentBundle::class => ['all' => true],
    ];
    
  2. Configuration: Define static pages in config/packages/c33s_static_page_content.yaml:

    c33s_static_page_content:
        pages:
            about:
                template: 'pages/about.html.twig'
                route: 'about_page'
            contact:
                template: 'pages/contact.html.twig'
                route: 'contact_page'
    
  3. First Use Case: Create a Twig template at templates/pages/about.html.twig:

    <h1>About Us</h1>
    <p>Static content here.</p>
    

    Access via route about_page (auto-generated by the bundle).


Where to Look First

  • Configuration: config/packages/c33s_static_page_content.yaml (primary config file).
  • Templates: templates/pages/ (default directory for Twig templates).
  • Documentation: Resources/doc/index.md (for advanced usage).

Implementation Patterns

Workflows

  1. Page Creation:

    • Add a new entry in c33s_static_page_content.pages config.
    • Create a corresponding Twig template.
    • Access via the auto-generated route (e.g., /about).
  2. Dynamic Content Injection: Pass variables to Twig templates via config:

    pages:
        about:
            template: 'pages/about.html.twig'
            route: 'about_page'
            vars:
                title: 'About Us'
                subtitle: 'Our Story'
    

    Use in Twig:

    <h1>{{ title }}</h1>
    <p>{{ subtitle }}</p>
    
  3. Route Customization: Override auto-generated routes by defining a custom route in routes.yaml:

    about_page:
        path: /our-company
        controller: C33s\StaticPageContentBundle\Controller\StaticPageController::renderAction
        defaults:
            page: 'about'
    
  4. Caching: Enable Twig cache for static pages in config/packages/twig.yaml:

    twig:
        cache: '%kernel.cache_dir%/twig'
    

Integration Tips

  • Symfony Flex: Works seamlessly with Symfony Flex projects.
  • Environment-Specific Templates: Use %kernel.environment% in template paths:
    pages:
        home:
            template: 'pages/home_%kernel.environment%.html.twig'
    
  • Dependency Injection: Access the StaticPageManager service in controllers:
    use C33s\StaticPageContentBundle\Manager\StaticPageManager;
    
    public function __construct(StaticPageManager $staticPageManager) {
        $this->staticPageManager = $staticPageManager;
    }
    

Gotchas and Tips

Pitfalls

  1. Unmaintained Package:

    • The bundle is unmaintained (as noted in the README). Consider alternatives like:
      • Symfony’s built-in renderWithoutController (docs).
      • Zero-Gravity CMS (recommended in the README).
    • Mitigation: Fork the repo if critical for your project.
  2. Route Conflicts:

    • Auto-generated routes (e.g., /about) may clash with existing routes.
    • Fix: Always define custom routes in routes.yaml or use _path helpers.
  3. Template Not Found:

    • Ensure templates are placed in the correct directory (templates/pages/ by default).
    • Debug: Check Symfony’s profiler for missing template errors.
  4. Configuration Overrides:

    • Bundle config is not merged with existing Symfony config. Overrides must be explicit:
      # config/packages/c33s_static_page_content.yaml
      c33s_static_page_content:
          pages:
              about:
                  template: 'custom/path/about.html.twig'  # Override
      

Debugging

  1. Check Config: Dump the loaded config to verify settings:

    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    public function __construct(ContainerInterface $container) {
        dump($container->getParameter('c33s_static_page_content.pages'));
    }
    
  2. Route Debugging: Use Symfony’s route debugger or CLI:

    php bin/console debug:router | grep about_page
    
  3. Twig Errors: Enable Twig debug mode in config/packages/dev/twig.yaml:

    twig:
        debug: '%kernel.debug%'
        strict_variables: '%kernel.debug%'
    

Extension Points

  1. Custom Template Locations: Override the template directory via config:

    c33s_static_page_content:
        template_dir: '%kernel.project_dir%/templates/custom_static_pages'
    
  2. Pre-Rendering Logic: Extend the StaticPageManager to add logic before rendering:

    // src/Service/CustomStaticPageManager.php
    use C33s\StaticPageContentBundle\Manager\StaticPageManager;
    
    class CustomStaticPageManager extends StaticPageManager {
        public function getContent(string $pageName) {
            $content = parent::getContent($pageName);
            // Add custom logic (e.g., modify vars)
            return $content;
        }
    }
    

    Register as a service in config/services.yaml:

    services:
        C33s\StaticPageContentBundle\Manager\StaticPageManager:
            alias: 'custom_static_page_manager'
            public: true
    
  3. Event Listeners: Listen to the static_page.render event to modify content dynamically:

    use C33s\StaticPageContentBundle\Event\StaticPageEvent;
    use Symfony\Component\EventDispatcher\GenericEvent;
    
    public function onStaticPageRender(StaticPageEvent $event) {
        $event->setContent($event->getContent() . '<div>Custom footer</div>');
    }
    

    Register the listener in config/services.yaml:

    services:
        App\EventListener\StaticPageListener:
            tags:
                - { name: 'kernel.event_listener', event: 'static_page.render', method: 'onStaticPageRender' }
    

Performance Tips

  1. Disable Debug Mode: Set kernel.debug: false in config/packages/dev/twig.yaml for production to leverage Twig caching.

  2. HTTP Caching: Add cache headers in a base Twig template:

    {% cache app.static_page('about') %}
        {# Static content here #}
    {% endcache %}
    
  3. Asset Optimization: Use Symfony’s asset mapper for static assets in templates:

    <img src="{{ asset('images/logo.png') }}" alt="Logo">
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor