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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageGallery - displaying specific Album Photos on other pages


Go to End


12 Posts   4321 Views

Avatar
alexbalanoff

Community Member, 8 Posts

9 December 2009 at 9:50am

Hi,

I've had a play with the ImageGallery module! Great Work by the way!!!

So what i've done is;

1. Created a brochure website, with templated inner pages.
2. Created one gallery with different albums (using the ImageGallery module)

What I'm trying to do is;

1. Display all the photos of a specific album on an inner page, so if I have two albums (in my gallery) called 'One' and 'Two', and I have two inner pages, called 'One' and 'Two' (so the Album names have the same names as the inner Pages) - I would like to display all the photos of album 'One' on the inner page called 'One', keeping in mind that the inner pages are using one template, so if I have an inner page called 'Twenty', I would like to display all the photos in the album named 'Twenty' :)

Look forward to the solution :)
Thanks

Avatar
UncleCheese

Forum Moderator, 4102 Posts

9 December 2009 at 10:56am

Here's how I would code that...

class MyPageWithAlbumOnIt extends Page
{
static $has_one = array (
'Album' => 'ImageGalleryAlbum'
);

public function getCMSFields() {
/// etc...
new DropdownField('AlbumID','Choose an album for this page',DataObject::get("ImageGalleryAlbum")->toDropdownMap('ID','AlbumName'));
}
}

class MyPageWithAlbumOnIt_Controller extends Page_Controller
{
public function AlbumLayout()
{
if($album = $this->Album()) {
$gallery = $this->Album()->ImageGalleryPage();
$gallery->current_album = $this->Album();
return $gallery->GalleryLayout();
}
return false
}
}

template..

$AlbumLayout

If setting the current_album property throws an error, let me know and I'll update the code to allow that.

Avatar
alexbalanoff

Community Member, 8 Posts

9 December 2009 at 6:25pm

Thanks heaps! Works like a charm! :)

Avatar
Rockshox

Community Member, 14 Posts

17 December 2009 at 3:09am

Edited: 17/12/2009 3:11am

Ah, this is exactly what I am looking for, but unfortunately I have not been able to get it to work.

The code I am using in place of the /// ect... is:

    $fields = parent::getCMSFields();	  
	
    $fields->addFieldToTab("Root.Content.Images", 

Can anyone give any suggestions as to where I am going wrong with this (I have also changed the "MyPageWithAlbumOnIt" to "GalleryPageTest").

Many thanks.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 December 2009 at 3:53am

I think the //etc in that case was just representing the usual stuff

$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Album", new DropdownField(....");
return $f;

Avatar
alexbalanoff

Community Member, 8 Posts

13 January 2010 at 3:14pm

hey UncleCheese,

I've just tried this same theory/ concept on another ne of my Silverstripe websites, using literally the same code, functions, etc. And the page which is supposed to be spitting out the images ... is not spitting out anything.

The only thing that I can say I've done differently is that I'm using the themes.
----
SSViewer::set_theme('ardent');
----
So I've got the imageGallery module working, I have 2 albums (with 2 photos in each album);
http://www.ardentinteractive.co.nz/portfolio-gallery

and the pop-ups work, etc.
I can associate (through the drop-down menu in the admin) the portfolio item with an album, but in my template when I call -
----
$AlbumLayout
----
It's most probably not running the function below (but it's odd because it doesn't throw an error);

----

class MyPageWithAlbumOnIt_Controller extends Page_Controller
{
public function AlbumLayout()
{
if($album = $this->Album()) {
$gallery = $this->Album()->ImageGalleryPage();
$gallery->current_album = $this->Album();
return $gallery->GalleryLayout();
}
return false
}
}

----

Any thoughts?

Avatar
Rishi

Community Member, 97 Posts

24 January 2010 at 10:09am

I am trying to do the same thing and have copied the code given byUncleCheese
but when I am trying to open admin panel its given me error message as
Parse error: parse error in D:\wamp\www\cs\mysite\code\MyPageWithAlbumOnIt.php on line 10

my code is

<?php
class MyPageWithAlbumOnIt extends Page
{
static $has_one = array (
'Album' => 'ImageGalleryAlbum'
);

public function getCMSFields() {
$f = parent::getCMSFields();

LINE NO 10 IS THE LINE BELOW
$f->addFieldToTab("Root.Content.Album", new DropdownField("...."); //error line

new DropdownField('AlbumID','Choose an album for this page',DataObject::get("ImageGalleryAlbum")->toDropdownMap('ID','AlbumName'))
return $f;
}
}

class MyPageWithAlbumOnIt_Controller extends Page_Controller
{
public function AlbumLayout()
{
if($album = $this->Album()) {
$gallery = $this->Album()->ImageGalleryPage();
$gallery->current_album = $this->Album();
return $gallery->GalleryLayout();
}
return false
}
}
?>

please help me out in solving this problem

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 January 2010 at 2:01pm

You're missing a closing parenthesis. Please be sure to check your syntax before posting code.

Go to Top