Installation Add the bundle via Composer:
composer require daemon/gallery-bundle
Enable it in config/bundles.php:
Daemon\GalleryBundle\DaemonGalleryBundle::class => ['all' => true],
Basic Configuration Publish the default config:
php bin/console daemon:gallery:install
Update config/packages/daemon_gallery.yaml (if needed) to match your asset paths (e.g., unitegallery_path).
First Use Case: Display a Gallery In a Twig template, render a gallery with:
{{ daemon_gallery({
'images': [
{ 'src': '/uploads/gallery/image1.jpg', 'thumb': '/uploads/gallery/thumbs/image1_thumb.jpg' },
{ 'src': '/uploads/gallery/image2.jpg', 'thumb': '/uploads/gallery/thumbs/image2_thumb.jpg' }
],
'theme': 'modern',
'effect': 'fade'
}) }}
unitegallery.js and unitegallery-themes.css are loaded in your base template (check assets/ after installation).Dynamic Gallery Generation Fetch images from a database (e.g., Doctrine entities) and pass them to the bundle:
// Controller
public function showGallery(Repository $imageRepo): Response
{
$images = $imageRepo->findAll();
$galleryData = array_map(function ($image) {
return [
'src' => $image->getFullPath(),
'thumb' => $image->getThumbPath(),
];
}, $images);
return $this->render('gallery/index.html.twig', [
'gallery' => $galleryData,
]);
}
Reusing Gallery Configs
Define reusable configurations in config/packages/daemon_gallery.yaml:
daemon_gallery:
presets:
blog_gallery:
theme: 'light'
effect: 'slide'
transition: 'cubic'
Use in Twig:
{{ daemon_gallery(galleryData|merge({'preset': 'blog_gallery'})) }}
Asset Management
unitegallery-themes.css or effects/ in public/assets/daemon_gallery/ and reference them in the config:
daemon_gallery:
theme_path: '%kernel.project_dir%/public/assets/daemon_gallery/themes/'
lazy option to defer initialization:
{{ daemon_gallery(galleryData|merge({'lazy': true})) }}
Integration with Forms For image uploads, pair with VichUploaderBundle:
// Entity
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[Vich\Uploadable]
class GalleryImage { ... }
Then pass the uploaded paths to the gallery bundle as shown above.
Asset Paths
unitegallery_path in config points to a non-existent directory.config/packages/daemon_gallery.yaml matches your public/ structure. Default is public/assets/daemon_gallery/.unitegallery.js or theme CSS files.Twig Template Not Found
DaemonGalleryBundle::base.html.twig), ensure the file exists in the bundle’s Resources/views/ or override it in your project.templates/bundles/daemon_gallery/base.html.twig and modify as needed.Image Paths Must Be Absolute
images/image.jpg) may break the gallery./uploads/images/image.jpg) or prepend {{ asset() }} in Twig:
{{ daemon_gallery({
'images': [
{ 'src': asset('uploads/image1.jpg'), 'thumb': asset('uploads/thumbs/image1_thumb.jpg') }
]
}) }}
Javascript Conflicts
$(document).ready() block or use the initCallback option:
{{ daemon_gallery(galleryData|merge({
'initCallback': 'function() { console.log("Gallery initialized"); }'
})) }}
Debugging
APP_DEBUG=true) to see detailed errors.Customization
templates/bundles/daemon_gallery/ directory.DaemonGallery Twig extension to add custom filters or functions.Performance
lazy: true to improve initial page load times.unitegallery.js and theme CSS in your base template:
<link rel="preload" href="{{ asset('assets/daemon_gallery/unitegallery-themes.css') }}" as="style">
<script src="{{ asset('assets/daemon_gallery/unitegallery.js') }}" defer></script>
Configuration
theme: 'modern', effect: 'fade'). Override only what’s necessary.%kernel.environment% to switch configs (e.g., dev vs. prod):
daemon_gallery:
debug: '%kernel.debug%'
Testing
DaemonGallery Twig extension in PHPUnit:
$twig = new \Twig\Environment($loader);
$twig->addExtension(new \Daemon\GalleryBundle\Twig\DaemonGalleryExtension());
How can I help you explore Laravel packages today?