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

Easybuilder Bundle Laravel Package

basic-builder/easybuilder-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require basic-builder/easybuilder-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        BasicBuilder\EasyBuilderBundle\EasyBuilderBundle::class => ['all' => true],
    ];
    
  2. First Use Case Generate a basic page template:

    php bin/console easybuilder:generate:page --name="HomePage" --template="default"
    

    This creates a new page under templates/easybuilder/pages/HomePage.html.twig.

  3. Key Directories

    • templates/easybuilder/ – Default location for generated templates.
    • config/easybuilder/ – Configuration files for builders.
    • src/EasyBuilder/ – Custom builder logic (if extending).

Implementation Patterns

Workflow: Page Generation

  1. Define a Template Create a base template in templates/easybuilder/base.html.twig:

    <!DOCTYPE html>
    <html>
    <head>
        <title>{% block title %}{% endblock %}</title>
    </head>
    <body>
        {% block content %}{% endblock %}
    </body>
    </html>
    
  2. Generate a Page Extend the base template:

    php bin/console easybuilder:generate:page \
        --name="About" \
        --extends="base" \
        --content="<h1>About Us</h1><p>Welcome to our site.</p>"
    
  3. Render Dynamically Use Twig in a controller:

    use BasicBuilder\EasyBuilderBundle\Twig\EasyBuilderExtension;
    
    public function showPage(EasyBuilderExtension $builderExtension)
    {
        $content = $builderExtension->render('About');
        return new Response($content);
    }
    

Integration with Symfony Forms

  1. Add Form Support Configure form types in config/easybuilder/forms.yaml:

    forms:
        contact:
            type: Symfony\Component\Form\Extension\Core\Type\FormType
            fields:
                - { name: "name", type: "text" }
                - { name: "email", type: "email" }
    
  2. Generate a Form Page

    php bin/console easybuilder:generate:page \
        --name="ContactForm" \
        --template="form" \
        --form="contact"
    
  3. Render in Twig

    {{ easybuilder_form('contact') }}
    

Dynamic Content with Twig Extensions

Extend Twig for reusable components:

// src/Twig/EasyBuilderCustomExtension.php
namespace App\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class EasyBuilderCustomExtension extends AbstractExtension
{
    public function getFunctions()
    {
        return [
            new TwigFunction('custom_component', [$this, 'renderComponent']),
        ];
    }

    public function renderComponent(string $name, array $data = [])
    {
        // Logic to render dynamic components
    }
}

Register in config/packages/twig.yaml:

twig:
    extensions:
        - App\Twig\EasyBuilderCustomExtension

Gotchas and Tips

Pitfalls

  1. Template Caching Clear the Twig cache after generating new templates:

    php bin/console cache:clear
    
  2. Namespace Conflicts Ensure custom builder classes are namespaced properly (e.g., App\EasyBuilder\CustomBuilder) to avoid collisions with the bundle’s default classes.

  3. Form Validation Errors If forms fail silently, check config/easybuilder/forms.yaml for missing constraints or incorrect field types. Validate with:

    php bin/console debug:form your_form_type
    
  4. Overwriting Default Templates Avoid naming custom templates the same as built-in ones (e.g., base.html.twig). Prefix with your bundle name (e.g., app_base.html.twig).

Debugging

  • Check Generated Files Verify templates are created in templates/easybuilder/ after generation commands fail.

  • Enable Twig Debugging Set debug: true in config/packages/twig.yaml to see template errors in detail.

  • Log Builder Events Enable logging in config/easybuilder.yaml:

    logging: true
    

Extension Points

  1. Custom Builders Extend the base builder class:

    // src/EasyBuilder/CustomBuilder.php
    namespace App\EasyBuilder;
    
    use BasicBuilder\EasyBuilderBundle\Builder\AbstractBuilder;
    
    class CustomBuilder extends AbstractBuilder
    {
        protected function configure()
        {
            $this->addOption('custom_option', null, 'Custom option value');
        }
    }
    

    Register in config/easybuilder.yaml:

    builders:
        custom:
            class: App\EasyBuilder\CustomBuilder
    
  2. Hooks for Pre/Post Generation Use Symfony events (e.g., easybuilder.page.generate) to modify generation logic:

    // src/EventListener/EasyBuilderListener.php
    namespace App\EventListener;
    
    use BasicBuilder\EasyBuilderBundle\Event\PageGenerateEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class EasyBuilderListener implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                PageGenerateEvent::NAME => 'onPageGenerate',
            ];
        }
    
        public function onPageGenerate(PageGenerateEvent $event)
        {
            $event->setContent($event->getContent() . '<!-- Custom footer -->');
        }
    }
    
  3. Asset Management Use Symfony’s asset system for generated pages:

    {% block stylesheets %}
        {{ parent() }}
        {{ encore_entry_link_tags('app') }}
    {% endblock %}
    

Configuration Quirks

  • YAML vs. PHP Config Prefer config/easybuilder.yaml for simplicity, but use config/easybuilder.php for complex logic (e.g., dynamic builder options).

  • Template Inheritance Ensure {% extends %} in generated templates matches existing base templates. Use absolute paths if needed:

    {% extends 'easybuilder/base.html.twig' %}
    
  • Command Arguments Use --dry-run to preview changes without generating files:

    php bin/console easybuilder:generate:page --name="Test" --dry-run
    
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