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

Layout Bundle Laravel Package

c33s-toolkit/layout-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require c33s-toolkit/layout-bundle
    

    Enable it in config/bundles.php:

    return [
        // ...
        C33S\Toolkit\LayoutBundle\C33SToolkitLayoutBundle::class => ['all' => true],
    ];
    
  2. First Use Case Extend the base layout in your Twig templates:

    {% extends 'c33s_layout_base.html.twig' %}
    {% block title %}My Page Title{% endblock %}
    {% block content %}
        <h1>Welcome!</h1>
    {% endblock %}
    
  3. Key Files

    • templates/c33s_layout_base.html.twig: The base layout template.
    • Resources/config/services.yaml: Configuration for layout services.

Implementation Patterns

Common Workflows

  1. Extending Layouts Override blocks in child templates:

    {% extends 'c33s_layout_base.html.twig' %}
    {% block header %}
        {{ parent() }} <!-- Include parent block -->
        <div class="custom-header">...</div>
    {% endblock %}
    
  2. Dynamic Layouts Use Twig logic to conditionally render sections:

    {% block sidebar %}
        {% if is_granted('ROLE_ADMIN') %}
            <div class="admin-sidebar">...</div>
        {% endif %}
    {% endblock %}
    
  3. Integration with Bootstrap3 Bundle Combine with bootstrap3-bundle for consistent styling:

    {% extends 'c33s_layout_base.html.twig' %}
    {% block stylesheets %}
        {{ parent() }}
        <link rel="stylesheet" href="{{ asset('css/custom.css') }}">
    {% endblock %}
    
  4. Service-Based Layouts Inject layout services in controllers:

    use C33S\Toolkit\LayoutBundle\Service\LayoutService;
    
    class HomeController extends AbstractController {
        public function index(LayoutService $layoutService) {
            return $this->render('home/index.html.twig', [
                'layout' => $layoutService->getLayoutData(),
            ]);
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Twig Block Inheritance Forgetting {% block %} or {% endblock %} will break layout rendering. Use {{ parent() }} to include parent block content.

  2. Symfony 3 Compatibility The bundle is designed for Symfony 3.x. Test thoroughly in Symfony 4+ if upgrading.

  3. Caching Issues Clear Twig cache after modifying templates:

    php bin/console cache:clear --env=prod
    

Debugging Tips

  • Check Template Paths: Ensure templates are in templates/ or a configured Twig path.
  • Log Layout Data: Use dump() in Twig to inspect passed variables:
    {{ dump(layout) }}
    

Extension Points

  1. Custom Layouts Override the base template by creating a new file (e.g., templates/base_custom.html.twig) and extend it in your templates.

  2. Layout Services Extend LayoutService to add custom logic:

    namespace App\Service;
    
    use C33S\Toolkit\LayoutBundle\Service\LayoutService;
    
    class CustomLayoutService extends LayoutService {
        public function getCustomData() {
            return ['key' => 'value'];
        }
    }
    
  3. Configuration Override bundle config in config/packages/c33s_toolkit_layout.yaml:

    c33s_toolkit_layout:
        default_layout: 'app_layouts/base.html.twig'
    
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