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

Simple Content Bundle Laravel Package

c33s/simple-content-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require c33s/simple-content-bundle:0.11.*
    

    Register the bundle in AppKernel.php:

    new C33s\SimpleContentBundle\C33sSimpleContentBundle(),
    
  2. Configure Locales: Ensure %locales% is defined in parameters.yml:

    parameters:
        locales: ['en', 'de']
    
  3. Enable Admin Generator (for editing): Install the dependency:

    composer require cedriclombardot/admingenerator-generator-bundle
    

    Generate the admin for C33sSimpleContentBundle:

    php app/console generate:admin C33sSimpleContentBundle:Content
    
  4. First Use Case: Wrap content in Twig templates with the provided filters (e.g., markdown, html). Example:

    {{ content|markdown }}
    

    Or for route-based content:

    {{ content_for_route('homepage')|html }}
    

Implementation Patterns

Core Workflow

  1. Define Content Blocks: Use Twig filters to mark content in templates as editable:

    <h1>{{ content|markdown('hero_title') }}</h1>
    <p>{{ content|html('hero_text') }}</p>
    
    • Filters: markdown, html, plaintext, route (for route-specific content).
  2. Route-Based Content: Assign content to routes via the admin interface (generated by admingenerator). Example:

    {{ content_for_route('about.page')|html }}
    
  3. Locale Handling: Enable fallback in config.yml:

    c33s_simple_content:
        use_locale_fallback: true
    

    Content will automatically fall back to the default locale if missing.

  4. Integration with Propel: The bundle uses Propel ORM for storage. Ensure your config.yml includes Propel:

    propel:
        dbal:
            connections:
                default: ~
    

Advanced Patterns

  • Dynamic Content Loading: Fetch content dynamically in controllers:

    $content = $this->get('c33s_simple_content.content_manager')->getContent('dynamic_key');
    return $this->render('template.html.twig', ['content' => $content]);
    
  • Custom Filters: Extend the bundle by creating custom Twig filters. Example:

    // src/C33s/SimpleContentBundle/Twig/Extension/CustomExtension.php
    class CustomExtension extends \Twig_Extension
    {
        public function getFilters()
        {
            return [
                new \Twig_SimpleFilter('custom_filter', [$this, 'customFilter']),
            ];
        }
    
        public function customFilter($content)
        {
            return strtoupper($content);
        }
    }
    

    Register the extension in services.yml:

    services:
        custom_extension:
            class: C33s\SimpleContentBundle\Twig\Extension\CustomExtension
            tags:
                - { name: twig.extension }
    
  • Batch Updates: Use the admin generator to update multiple content blocks in bulk via the generated CRUD interface.


Gotchas and Tips

Pitfalls

  1. Admin Generator Dependency:

    • The bundle relies on admingenerator-generator-bundle for content editing. If this bundle is removed or updated, the admin interface may break.
    • Fix: Pin the dependency version in composer.json:
      "cedriclombardot/admingenerator-generator-bundle": "~1.0"
      
  2. Propel Schema Mismatch:

    • The bundle assumes a Propel schema for the Content table. If your Propel schema doesn’t match, content may not save or load correctly.
    • Fix: Check the bundle’s migrations or manually adjust your schema to include:
      <table name="content" phpName="Content">
          <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
          <column name="key" type="varchar" size="255" required="true" />
          <column name="content" type="longvarchar" />
          <column name="locale" type="varchar" size="10" required="true" />
          <column name="type" type="varchar" size="50" required="true" />
      </table>
      
  3. Locale Fallback Quirks:

    • With use_locale_fallback: true, missing locales will fall back to the first locale in parameters.yml. Ensure the default locale is always defined.
    • Tip: Test fallback behavior by temporarily removing a locale’s content to verify the fallback works as expected.
  4. Twig Filter Caching:

    • Twig filters like markdown may cache processed content. Clear the cache after updating content:
      php app/console cache:clear
      

Debugging Tips

  1. Check Content Keys:

    • Typos in content keys (e.g., hero_title vs. heroTitle) will result in empty output. Validate keys in the admin interface.
  2. Propel Debugging:

    • Enable Propel logging in config.yml:
      propel:
          logging: true
      
    • Check logs at app/logs/prod.log (or dev.log) for Propel-related errors.
  3. Admin Generator Issues:

    • If the admin interface fails to load, clear the cache and regenerate the admin:
      php app/console cache:clear
      php app/console generate:admin C33sSimpleContentBundle:Content
      

Extension Points

  1. Custom Content Types: Extend the Content model to support additional fields (e.g., priority, published_at). Update the Propel schema and admin generator templates accordingly.

  2. Override Twig Filters: Replace or extend existing filters by creating a custom Twig extension (as shown in Advanced Patterns). Example:

    {{ content|custom_markdown('key') }}
    
  3. Route-Based Content Logic: Add custom logic to the content_for_route filter by overriding the bundle’s Twig extension:

    // src/C33s/SimpleContentBundle/Resources/config/services.yml
    services:
        c33s_simple_content.twig.extension:
            class: Your\Bundle\Twig\SimpleContentExtension
            arguments: [@c33s_simple_content.content_manager]
            tags:
                - { name: twig.extension }
    
  4. Event Listeners: Listen for content updates to trigger side effects (e.g., cache invalidation):

    // src/YourBundle/EventListener/ContentListener.php
    class ContentListener
    {
        public function onContentUpdate(GetResponseEvent $event)
        {
            // Invalidate cache or perform other actions
        }
    }
    

    Register the listener in services.yml:

    services:
        your_bundle.content_listener:
            class: Your\Bundle\EventListener\ContentListener
            tags:
                - { name: kernel.event_listener, event: kernel.response, method: onContentUpdate }
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui