Installation
composer require atlantic18/coral-site-bundle
Add to config/bundles.php:
return [
// ...
Atlantic18\CoralSiteBundle\Atlantic18CoralSiteBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console coral:site:init
Edit config/packages/coral_site.yaml to define:
local, github, dropbox)yaml, annotation, or php)First Use Case: Rendering a Page
Define a content file (e.g., content/home.yaml):
title: "Welcome"
content: "<h1>Hello, Coral!</h1>"
Create a route in config/routes/coral.yaml:
home:
path: /
defaults: { _controller: 'Atlantic18CoralSiteBundle:Page:render', content: 'home' }
Run the dev server and visit /.
Storage Integration
Use the CoralStorageInterface to integrate custom storage backends (e.g., S3, custom DB):
// config/packages/coral_site.yaml
coral_site:
storage:
driver: 'custom'
options:
connection: 's3://your-bucket'
Implement Atlantic18\CoralSiteBundle\Storage\CoralStorageInterface for your driver.
Dynamic Routing
Leverage the CoralRouter to handle routes dynamically:
// src/Controller/CustomController.php
use Atlantic18\CoralSiteBundle\Routing\CoralRouter;
class CustomController extends AbstractController {
public function __invoke(CoralRouter $router, string $contentId) {
return $this->renderContent($contentId);
}
}
Define routes in config/routes/coral.yaml:
dynamic_route:
path: /content/{id}
defaults: { _controller: 'App\Controller\CustomController' }
Twig Integration Extend Twig templates with Coral-specific logic:
{% extends 'base.html.twig' %}
{% block content %}
{{ coral_content('home').render() }}
{# Render a specific content block #}
{{ coral_content('home').getBlock('hero') }}
{% endblock %}
Register the Twig extension in config/packages/twig.yaml:
twig:
globals:
coral_content: '@atlantic18_coral_site.twig.content_loader'
Content Branching Use GitHub/GitLab for content versioning:
# coral_site.yaml
coral_site:
storage:
driver: 'github'
options:
repo: 'your-org/your-repo'
branch: 'main'
token: '%env(GITHUB_TOKEN)%'
Pull changes via:
php bin/console coral:site:pull
Caching Quirks Coral caches content aggressively. Clear caches after storage changes:
php bin/console cache:clear
php bin/console coral:site:clear-cache
Override cache behavior in coral_site.yaml:
coral_site:
cache:
enabled: false
ttl: 3600
Route Precedence Coral routes take precedence over Symfony’s default router. Ensure no conflicts:
# config/routes.yaml
_coral:
resource: "@Atlantic18CoralSiteBundle/Resources/config/routing.yaml"
prefix: /
Place Coral routes after other routes in routes.yaml.
Content Loading Order Content files are loaded alphabetically. Prefix files with numbers for ordering:
content/01_home.yaml
content/02_about.yaml
Enable Debug Mode
# coral_site.yaml
coral_site:
debug: true
Logs detailed content loading events to var/log/coral_site.log.
Validate Content Structure
Use the coral:site:validate command to check YAML syntax:
php bin/console coral:site:validate
Storage Connection Issues For GitHub/Dropbox, ensure:
repo/files permissions.webhook driver).Custom Content Types
Extend Atlantic18\CoralSiteBundle\Model\ContentInterface:
class CustomContent implements ContentInterface {
public function getCustomField() { /* ... */ }
}
Register the type in coral_site.yaml:
coral_site:
content_types:
custom: 'App\Model\CustomContent'
Event Listeners
Listen for content events (e.g., ContentLoadEvent):
// src/EventListener/CoralListener.php
use Atlantic18\CoralSiteBundle\Event\ContentLoadEvent;
class CoralListener {
public function onContentLoad(ContentLoadEvent $event) {
if ($event->getContent()->getId() === 'home') {
$event->setContent($this->modifyContent($event->getContent()));
}
}
}
Bind in services.yaml:
services:
App\EventListener\CoralListener:
tags:
- { name: 'kernel.event_listener', event: 'coral.content.load' }
Override Templates
Override Coral’s default templates in templates/Atlantic18CoralSiteBundle/:
templates/
Atlantic18CoralSiteBundle/
Page/
render.html.twig {# Override page rendering #}
How can I help you explore Laravel packages today?