Reputation: 499
I have built an image gallery module using lightboxes and effects. What I want to do is include the css and js requirements on the GalleryController rather than the PageController but it doesn't seem to work.
I have a Gallery which extends DataExtension and then I have a GalleryController which extends Extension. Then in my _config file I point the ContentController to my GalleryController:
SiteTree::add_extension('Gallery');
Object::add_extension('ContentController', 'GalleryController');
The GalleryController is working as it is getting the Gallery objects for me. It is the requirements on this controller that aren't working.
GalleryController:
public function init() {
parent::init();
//Load CSS requirements
Requirements::css("ImageGallery/css/lightgallery.min.css");
//Load Javascript requirements
Requirements::javascript("ImageGallery/js/lightgallery.min.js");
Do I need to do something else to include requirements on another controller that isn't PageController?
Upvotes: 2
Views: 166
Reputation: 24406
Extensions in SilverStripe don't allow you to overload the public API, you can only augment it. It looks like this is what you're trying to do with the GalleryController extension.
In this case you'll see that ContentController::init
provides an extension point contentcontrollerInit
on the SiteTree object - you should use that to add your requirements. This can be added to your Gallery DataExtension class:
# Class: Gallery.php
public function contentcontrollerInit()
{
Requirements::javascript('...');
}
Upvotes: 6