Install the Bundle
composer require azine/socialbar-bundle
Enable the bundle in config/bundles.php:
return [
// ...
Azine\SocialBarBundle\AzineSocialBarBundle::class => ['all' => true],
];
Configure Social Profiles
Add your social profile URLs/IDs in config/packages/azine_social_bar.yaml:
azine_social_bar:
fb_profile_url: "https://facebook.com/yourpage"
twitter_username: "yourhandle"
google_plus_profile_url: "https://plus.google.com/yourprofile"
linked_in_company_id: "12345678"
xing_profile_url: "https://www.xing.com/profile/yourprofile"
Render in Twig
Use the azine_socialbar Twig function in your templates:
{{ azine_socialbar() }}
This renders a default social bar with buttons for Facebook, Twitter, Google+, LinkedIn, and Xing.
Place the azine_socialbar() call in your base template (e.g., base.html.twig) to ensure it appears on every page:
<body>
<!-- Page content -->
{{ azine_socialbar() }}
</body>
Override the default configuration per environment or per template:
# config/packages/dev/azine_social_bar.yaml
azine_social_bar:
fb_profile_url: "https://facebook.com/devpage"
Extend the Twig function or pass options:
{{ azine_socialbar({
'show_facebook': false,
'show_twitter': true,
'show_google_plus': true,
'button_style': 'standard' // 'standard', 'box_count', or 'button_count'
}) }}
Fetch social profiles dynamically from a database:
{% set socialConfig = {
'fb_profile_url': app.user.facebookUrl,
'twitter_username': app.user.twitterHandle
} %}
{{ azine_socialbar(socialConfig) }}
The bundle supports language-specific buttons (e.g., es_ES for Spanish). Pass the locale:
{{ azine_socialbar({'locale': 'es_ES'}) }}
Missing Configuration
If fb_profile_url or twitter_username is empty, the corresponding buttons will not render. Validate these in your config or via Twig:
{% if app.parameters.azine_social_bar.fb_profile_url %}
{{ azine_socialbar({'show_facebook': true}) }}
{% endif %}
Button Styling Conflicts
The bundle injects inline styles for buttons. If your theme overrides these, ensure specificity or use button_style: 'custom' and manually style the buttons via CSS classes (e.g., .fb-like, .twitter-follow-button).
CORS Issues with LinkedIn
LinkedIn’s follow button may fail if your site lacks proper CORS headers. Ensure your server allows requests to *.linkedin.com.
Deprecated Symfony 3.x
The bundle targets Symfony 3.x. For Symfony 4/5, test compatibility or fork the package to update dependencies (e.g., symfony/twig-bridge).
Inspect Rendered HTML Check the Twig output for malformed URLs or missing attributes. Use browser dev tools to verify button scripts are loaded.
Clear Cache After Config Changes
Run php bin/console cache:clear if buttons fail to update after modifying config/packages/azine_social_bar.yaml.
Validate Social URLs Test each profile URL in a browser to ensure they’re publicly accessible (e.g., LinkedIn Company IDs must be verified).
Custom Button Templates
Override the Twig template at templates/AzineSocialBar/socialbar.html.twig to modify the layout or add buttons (e.g., Pinterest, Reddit).
Event Listeners
Extend functionality via Symfony events. For example, listen to kernel.request to dynamically set twitter_username based on the current user:
// src/EventListener/SocialBarListener.php
public function onKernelRequest(GetResponseEvent $event) {
$request = $event->getRequest();
$this->container->getParameterBag()->set('azine_social_bar.twitter_username', $request->get('user')?->getTwitterHandle());
}
Add New Social Networks
Fork the bundle and extend the SocialBarService to support additional platforms (e.g., Mastodon). Update the Twig template to include new buttons.
Lazy-Load Buttons Defer non-critical buttons (e.g., Xing) by default and load them via JavaScript if needed:
{{ azine_socialbar({'show_xing': false}) }}
<script>
// Load Xing button dynamically
</script>
Combine Scripts Minify and combine the social button scripts (Facebook, Twitter, etc.) into a single file to reduce HTTP requests. Use a build tool like Webpack or Laravel Mix.
How can I help you explore Laravel packages today?