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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageGallery - displaying specific Album Photos on other pages


Go to End
Reply

12 Posts   2469 Views

Avatar
alexbalanoff

9 December 2009 at 9:50am Community Member, 8 Posts

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

9 December 2009 at 10:56am 4085 Posts

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

9 December 2009 at 6:25pm Community Member, 8 Posts

Thanks heaps! Works like a charm! :)

Avatar
Rockshox

17 December 2009 at 3:09am (Last edited: 17 December 2009 3:11am), Community Member, 14 Posts

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

17 December 2009 at 3:53am 4085 Posts

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

13 January 2010 at 3:14pm Community Member, 8 Posts

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

24 January 2010 at 10:09am Community Member, 97 Posts

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

24 January 2010 at 2:01pm 4085 Posts

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

Go to Top