Installation
composer require cedricziel/shariff-bundle
Enable the bundle in config/bundles.php:
CedricZiel\ShariffBundle\CedricZielShariffBundle::class => ['all' => true],
Routing
Add to config/routes.yaml:
cedricziel_shariff:
resource: "@CedricZielShariffBundle/Resources/config/routing.xml"
prefix: /_shariff
Basic Configuration
Add to config/packages/cedricziel_shariff.yaml:
cedricziel_shariff:
domain: 'yourdomain.com'
force_protocol: https # or http
First Use Case Embed Shariff in a Twig template:
{{ render(controller('CedricZielShariffBundle:Shariff:render', {
'url': app.request.getUri(),
'title': 'Your Page Title',
'theme': 'heise'
})) }}
Dynamic URL Sharing Pass dynamic URLs/titles from controllers:
// src/Controller/ArticleController.php
public function show(Article $article): Response
{
return $this->render('article/show.html.twig', [
'shariff_data' => [
'url' => $this->generateUrl('article_show', ['id' => $article->id]),
'title' => $article->title,
],
]);
}
In Twig:
{% if shariff_data %}
{{ render(controller('CedricZielShariffBundle:Shariff:render', shariff_data)) }}
{% endif %}
Theme Customization Override default themes by extending the bundle’s templates:
templates/
└── CedricZielShariffBundle/
└── Shariff/
└── render.html.twig # Customize here
Caching Strategy Leverage Symfony’s cache for performance:
cedricziel_shariff:
cache:
cacheDir: '%kernel.cache_dir%/shariff'
lifetime: 3600 # 1 hour
Service Integration
Use the ShariffService in services:
// src/Service/MyService.php
public function __construct(private ShariffService $shariff)
{
}
public function generateShareCode(): string
{
return $this->shariff->render(
url: '/current-url',
title: 'Dynamic Title',
theme: 'heise'
);
}
Protocol Mismatch
force_protocol is misconfigured, Shariff may fail to load due to mixed-content warnings.force_protocol matches your site’s actual protocol (e.g., https for production).Caching Issues
php bin/console cache:clear
Domain Configuration
yourdomain.com vs. www.yourdomain.com).*.yourdomain.com) or configure multiple domains in domain:
cedricziel_shariff:
domain: ['yourdomain.com', 'www.yourdomain.com']
Twig Rendering Errors
render() fails, check:
/_shariff) is accessible.url, title) are passed./_shariff/render returns a 200 status.config/packages/cedricziel_shariff.yaml:
cedricziel_shariff:
debug: true # Logs configuration to Symfony's log channel
Custom Services
Extend ShariffService to add logic:
// src/Service/CustomShariffService.php
class CustomShariffService extends ShariffService
{
public function renderWithAnalytics(array $options): string
{
$options['analytics'] = true;
return parent::render($options);
}
}
Register as a service override:
services:
CedricZiel\ShariffBundle\Service\ShariffService: '@app.custom_shariff_service'
Event Listeners
Hook into Shariff events (e.g., shariff.render) to modify behavior:
// src/EventListener/ShariffListener.php
class ShariffListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ShariffEvents::RENDER => 'onRender',
];
}
public function onRender(RenderEvent $event): void
{
$event->setTheme('custom-theme');
}
}
Theme Overrides Copy the default theme from:
vendor/cedricziel/shariff-bundle/Resources/views/Shariff/
To your project’s templates/CedricZielShariffBundle/Shariff/ and modify.
How can I help you explore Laravel packages today?