bitbirddev/twig-components-bundle
Installation:
composer require bitbirddev/twig-components-bundle
Ensure bitbirddev/web-components and vidstack/player are also installed (handled automatically via dependencies).
Register the Bundle:
Add to config/bundles.php:
return [
// ...
BitbirdDev\TwigComponentsBundle\BitbirdDevTwigComponentsBundle::class => ['all' => true],
];
First Use Case: Embed a YouTube video in a Twig template:
<twig:media-player video="https://www.youtube.com/watch?v=DFYRQ_zQ-gk" />
Verify the bundle is registered by checking if the twig:media-player tag renders the player.
pimcore_video(), pimcore_asset()).config/packages/bitbirddev_twig_components.yaml for default settings (e.g., privacy wall options).templates/bundles/BitbirdDevTwigComponents/media_player.html.twig.Pimcore Integration:
pimcore_video() or pimcore_asset() for CMS-managed videos:
<twig:media-player :video="pimcore_video('video_field_name')" />
VideoHandler (see README).Dynamic Sources: Pass an array of sources for adaptive playback:
<twig:media-player :video="['/path/to/video.mp4', '//cdn.example.com/fallback.mp4']" />
Privacy Wall (Usercentrics):
Enable via config (usercentrics: true) and pass consent status:
<twig:media-player video="..." consent="{{ consent_status }}" />
VidStack Customization: Extend the player’s capabilities by passing VidStack-specific attributes:
<twig:media-player video="..." :config="{
'controls': false,
'autoplay': true
}" />
Asset Pipeline:
Use the class attribute to apply CSS classes for styling:
<twig:media-player video="..." class="w-full max-w-md" />
Lazy Loading:
Combine with Twig’s {% autoescape %} or JavaScript lazy-load libraries for performance.
Pimcore-Specific Dependencies:
pimcore_video() helper. Without Pimcore, use raw URLs or implement a VideoHandler for your ORM.VideoResolver service.Privacy Wall Misconfiguration:
usercentrics is enabled but consent logic is missing, videos may fail to load.consent is passed to the component or handle it via JavaScript.VidStack Version Conflicts:
The bundle pins vidstack/player to a specific version. Upgrades may break compatibility.
composer.json and test thoroughly after updates.CORS Issues:
Direct asset URLs (e.g., http://example.com/video.mp4) may block playback due to CORS.
Template Overrides:
If the component renders unexpectedly, verify overrides in templates/bundles/BitbirdDevTwigComponents/.
Clear cache (php bin/console cache:clear) after changes.
Console Logs: VidStack emits errors to the browser console. Inspect for:
Failed to load resource (CORS/URL issues).Invalid source (malformed input).Custom Video Handlers:
Extend the BitbirdDev\TwigComponentsBundle\Video\VideoHandlerInterface to support non-Pimcore sources:
// src/Service/CustomVideoHandler.php
class CustomVideoHandler implements VideoHandlerInterface {
public function resolve($input): string {
// Transform input (e.g., API response) into a playable URL.
return $playableUrl;
}
}
Register as a service with the tag bitbirddev.twig_components.video_handler.
Twig Extensions:
Add custom attributes to the component by extending the MediaPlayerExtension:
// src/Twig/MediaPlayerExtension.php
class CustomMediaPlayerExtension extends \BitbirdDev\TwigComponentsBundle\Twig\MediaPlayerExtension {
public function getFunctions() {
return array_merge(parent::getFunctions(), [
new \Twig\TwigFunction('custom_media_player', [$this, 'renderCustomPlayer']),
]);
}
}
Configuration Overrides:
Override default settings in config/packages/bitbirddev_twig_components.yaml:
bitbirddev_twig_components:
media_player:
default_config:
controls: true
autoplay: false
usercentrics:
enabled: true
consent_attribute: 'data-consent'
preload config to hint browsers about resource priority:
<twig:media-player :video="..." :config="{'preload': 'auto'}" />
How can I help you explore Laravel packages today?