Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageGallery - displaying specific Album Photos on other pages

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2262 Views
  • alexbalanoff
    Avatar
    Community Member
    8 Posts

    ImageGallery - displaying specific Album Photos on other pages Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

    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.

  • alexbalanoff
    Avatar
    Community Member
    8 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

    Thanks heaps! Works like a charm!

  • Rockshox
    Avatar
    Community Member
    14 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

    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;

  • alexbalanoff
    Avatar
    Community Member
    8 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

    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?

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageGallery - displaying specific Album Photos on other pages Link to this post

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

    2262 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.