Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

<% require %> am I doing it right? Image gallery setup.


Go to End


4 Posts   1219 Views

Avatar
Scorpiankh

Community Member, 63 Posts

8 June 2015 at 2:11pm

Edited: 08/06/2015 2:12pm

HI
I'm trying to get the image gallery module up and running on a new website, used <% require %> to call in the css and javascript, it's half working so I must have done something right, I'm just not sure where I'm going wrong ...

I've got:

public function init() {
		parent::init();
		// You can include any CSS or JS required by your project here.
		// See: http://doc.silverstripe.org/framework/en/reference/requirements
		Requirements::css("ImageGallery/css/ImageGallery.css");
		Requirements::css("ImageGallery/gallery_ui/fancybox/css/fancy.css");
		Requirements::javascript("ImageGallery/javascript/imagegallery_init.js");
		Requirements::javascript("ImageGallery/gallery_ui/fancybox/javascript/jquery.fancybox.js");
		Requirements::javascript("ImageGallery/gallery_ui/fancybox/javascript/jquery.pngFix.pack.js");
		Requirements::javascript("ImageGallery/gallery_ui/fancybox/javascript/lightbox_init.js");
	}

in the page.php file,
and

 <% require CSS('ImageGallery/css/ImageGallery.css') %>
	<% require CSS('ImageGallery/gallery_ui/fancybox/css/fancy.css') %>

in the head tags on Page.ss
and
<% require javascript('ImageGallery/javascript/imagegallery_init.js') %>
<% require javascript('ImageGallery/gallery_ui/fancybox/javascript/jquery.fancybox.js') %>
<% require javascript('ImageGallery/gallery_ui/fancybox/javascript/jquery.pngFix.pack.js') %>
<% require javascript('ImageGallery/gallery_ui/fancybox/javascript/lightbox_init.js') %>

below the footer, within the body tag on Page.ss ...

The gallery is KIND OF working, i've got albums, images, etc; css is working for albums and gallery pages, but when I click on the image in the gallery it opens in a blank window instead of in the popup window like it should.
I'm not sure if i've done something wrong in the requirements and the javascript isn't working at all, or if I've done the requirements right and it's just whatever is inside the 'gallery_ui' folder that isn't being called.

I've not used SS for a while so I'm more than a little rusty, and I've never used requirements before ... and sure it's something really silly .. but any help would be appreciated.

Ta

Avatar
Pyromanik

Community Member, 419 Posts

9 June 2015 at 9:13am

Hmm, interestingly enough it might be a limitation. Try it without the underscore (ie, remove it from both the code and the folder name obviously) and see if the issue persists.

You've obviously got it right otherwise as the other parts are working.
Although, you don't need to require things twice. Do it either from the php or from the template. Both is a little confusing (and maintenance heavy).

Avatar
Scorpiankh

Community Member, 63 Posts

10 June 2015 at 2:34pm

Edited: 10/06/2015 2:39pm

Hi, thanks for your reply ... I tried removing the underscore from the code and the folder name but that didn't make any difference.
(and removed the require tags from the template, thanks for that tip, the documentation on requirements was a bit vague)

If I've done the requirements right and it's still not working I'm not sure what else the problem could be, it's only that one bit that won't work, the gallery popup and I tried different ones, lightbox, fancybox, pretty photo etc, but same thing with all of them .....

Avatar
Scorpiankh

Community Member, 63 Posts

10 June 2015 at 3:18pm

ok, never mind, got it working, there were 2 problems, 1 there was a requirement missing, and 2, the requirements seemed to only work in the .ss file.
All good now. Nothing to see here, move along...