Installation:
composer require c33s/simple-content-bundle:0.11.*
Register the bundle in AppKernel.php:
new C33s\SimpleContentBundle\C33sSimpleContentBundle(),
Configure Locales:
Ensure %locales% is defined in parameters.yml:
parameters:
locales: ['en', 'de']
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
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 }}
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>
markdown, html, plaintext, route (for route-specific content).Route-Based Content:
Assign content to routes via the admin interface (generated by admingenerator). Example:
{{ content_for_route('about.page')|html }}
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.
Integration with Propel:
The bundle uses Propel ORM for storage. Ensure your config.yml includes Propel:
propel:
dbal:
connections:
default: ~
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.
Admin Generator Dependency:
admingenerator-generator-bundle for content editing. If this bundle is removed or updated, the admin interface may break.composer.json:
"cedriclombardot/admingenerator-generator-bundle": "~1.0"
Propel Schema Mismatch:
Content table. If your Propel schema doesn’t match, content may not save or load correctly.<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>
Locale Fallback Quirks:
use_locale_fallback: true, missing locales will fall back to the first locale in parameters.yml. Ensure the default locale is always defined.Twig Filter Caching:
markdown may cache processed content. Clear the cache after updating content:
php app/console cache:clear
Check Content Keys:
hero_title vs. heroTitle) will result in empty output. Validate keys in the admin interface.Propel Debugging:
config.yml:
propel:
logging: true
app/logs/prod.log (or dev.log) for Propel-related errors.Admin Generator Issues:
php app/console cache:clear
php app/console generate:admin C33sSimpleContentBundle:Content
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.
Override Twig Filters: Replace or extend existing filters by creating a custom Twig extension (as shown in Advanced Patterns). Example:
{{ content|custom_markdown('key') }}
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 }
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 }
How can I help you explore Laravel packages today?