Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » Gallery: show image details

Discuss all other Modules here.

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

Page: 1 2 3 4
Go to End
Author Topic: 4705 Views
  • DinaHansen
    Avatar
    Community Member
    10 Posts

    Gallery: show image details Link to this post

    Hi
    I am working on a site for a gallery. I have searched everywhere (i think) looking for at gallery module, where I can include image details with the image. I have the ImageGallery installed atm, but I have difficulties working with it.

    What I need is to be able to write something like this:

    Name of the painting
    Painter: Bla bla...
    Year painted: Bla bla...
    dimensions: Bla bla...

    The text doens't need to show in fx. shadowbox (my chosen image viewer), but in the gallery page beside the image.

    any help folks?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Gallery: show image details Link to this post

    ImageGallery allows you to subclass all of its components, so this should be no problem.

    class MyGallery extends ImageGalleryPage
    {
    protected $itemClass = "MyImageGalleryItem";
    }

    class MyImageGalleryItem extends ImageGalleryItem
    {
    static $db = array (
    'PaintingName' => 'Varchar(255)',
    'Year' => 'Int'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new TextField('PaintingName','Name of painting'));
    $f->push(new TextField('Year'));
    return $f;
    }
    }

    If you're using Shadowbox as your chosen GalleryUI, then you'll need to override Shadowbox_item.ss

    /your_theme/templates/Shadowbox_item.ss

    <a id="ViewLink-$ID" rel="shadowbox[gallery]" class="shadowbox" title="$Caption.EscapeXML" href="$ViewLink">
       <img src="$ThumbnailURL" alt="$Title.EscapeXML"/>
    </a>
    <h3>$PaintingName</h3>
    <h4>$Year</h4>

    Run /dev/build.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Gallery: show image details Link to this post

    Sorry, my bad. You need to override GalleryUI_layout.ss

    /your_theme/templates/Includes/GalleryUI_layout.ss

          <% if GalleryItems %>
          <ul class="gallery-layout" id="gallery-list">
             <% if GalleryItems.NotFirstPage %>
                <% control PreviousGalleryItems %>
                         <li style="display:none;">$GalleryItem</li>
                <% end_control %>
             <% end_if %>
             <% control GalleryItems %>
                <li style="height:{$ThumbnailHeight}px;width:{$ThumbnailWidth}px;">
                      $GalleryItem
    <h3>$PaintingName</h3>
    <h4>$Year</h4>
                </li>
             <% end_control %>
             <% if GalleryItems.NotLastPage %>
                <% control NextGalleryItems %>
                   <li style="display:none;">$GalleryItem</li>
                <% end_control %>
             <% end_if %>
          </ul>
          <% end_if %>

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Gallery: show image details Link to this post

    Hi this is great exactly what I also needed. However Im having problems, Im new to the classes and php etc and I'm not sure where to put the code.

    Question1.
    I created MyGallery.php from your example and placed it in the ImageGallery code folder:

    <?php
    class MyGallery extends ImageGalleryPage
    {
    protected $itemClass = "MyImageGalleryItem";
    }

    class MyImageGalleryItem extends ImageGalleryItem
    {
    static $db = array (
    'PaintingName' => 'Varchar(100)',
    'PaintingDimensions' => 'Varchar(50)',
    'Media' => 'Varchar(50)'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new TextField('PaintingName','Name of painting'));
    $f->push(new TextField('PaintingDimensions','Dimensions of painting'));
    $f->push(new TextField('Media','Media'));
    return $f;
    }
    }
    ?>

    After a dev/build I got this error:


    [User Error] Couldn't run query: SELECT `ImageGalleryItem`.*, `MyImageGalleryItem`.*, `ImageGalleryItem`.ID, if(`ImageGalleryItem`.ClassName,`ImageGalleryItem`.ClassName,'ImageGalleryItem') AS RecordClassName FROM `ImageGalleryItem` LEFT JOIN `MyImageGalleryItem` ON `MyImageGalleryItem`.ID = `ImageGalleryItem`.ID WHERE ((AlbumID='15') AND (`ImageGalleryPageID` = '11')) ORDER BY SortOrder ASC LIMIT 0,10 Table 'jacquifenn.MyImageGalleryItem' doesn't exist

    Sorry if this is a very obvious mistake but could you please advise me of exactly where and how to use the code?
    I also changed the UI_layout as you described.

    Question 2.

    I also need a sold feature which will show a red dot next to the painting description.
    Could you please suggest a way to do this?
    i.e. a check box 'sold [ ]' in the pop up menu for each gallery item if ticked it shows a red dot, perhaps a jpg, next to the PaintingName.

    Thank you for your time and any help!! much appreciated.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Gallery: show image details Link to this post

    1) Don't put anything in the image_gallery/code folder. You should never have to make alterations to the core module code. Add these classes to your mysite/code.

    2) Each class needs its own file. You need to create MyImageGalleryPage.php AND MyImageGalleryItem.php each containing their corresponding PHP class.

    3) To get your checkbox, just update your db fields and your fieldset in MyImageGalleryItem.php

    static $db = array (
    'PaintingName' => 'Varchar(100)',
    'PaintingDimensions' => 'Varchar(50)',
    'Media' => 'Varchar(50)' ,
    'Sold' => 'Boolean'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new TextField('PaintingName','Name of painting'));
    $f->push(new TextField('PaintingDimensions','Dimensions of painting'));
    $f->push(new TextField('Media','Media'));
    $f->push(new CheckboxField('Sold','This painting is sold'));
    return $f;
    }
    }

  • DinaHansen
    Avatar
    Community Member
    10 Posts

    Re: Gallery: show image details Link to this post

    thanks alot, I'll try make the changes!

    /Dina

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Gallery: show image details Link to this post

    Hi sorry to be a pain but I can't get this to work. I've been reading the tutorials but don't understand. I've created:

    MyImageGalleryItem.php

    <?php
    class MyGallery extends ImageGalleryPage
    {
    protected $itemClass = "MyImageGalleryItem";
    }

    class MyImageGalleryItem extends ImageGalleryItem
    {
    static $db = array (
    'PaintingName' => 'Varchar(100)',
    'PaintingDimensions' => 'Varchar(50)',
    'Media' => 'Varchar(50)' ,
    'Sold' => 'Boolean'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new TextField('PaintingName','Name of painting'));
    $f->push(new TextField('PaintingDimensions','Dimensions of painting'));
    $f->push(new TextField('Media','Media'));
    $f->push(new CheckboxField('Sold','This painting is sold'));
    return $f;
    }
    }
    ?>

    & MyImageGalleryPage.php

    <?php
    /**
    * Defines the MyImageGalleryPage page type
    */

    class MyImageGalleryPage extends ImageGallery {
    static $db = array(
    );
    static $has_one = array(
    );

    }

    class MyImageGalleryPage_Controller extends ImageGallery_Controller {
       
    }
    ?>

    and placed these in mysite/code,
    but again this just gives me errors after dev/build..?

    Also how will the check box effect the actual page, if its ticked, how does this effect the page? (as I want this to be 'if ticked add image x.jpg' where $Sold appears)

    THANKS for your patience!!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Gallery: show image details Link to this post

    You've got this a little backwards.

    mysite/code/MyImageGalleryItem.php

    class MyImageGalleryItem extends ImageGalleryItem
    {
    static $db = array (
    'PaintingName' => 'Varchar(100)',
    'PaintingDimensions' => 'Varchar(50)',
    'Media' => 'Varchar(50)' ,
    'Sold' => 'Boolean'
    // etc...
    );

    public function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new TextField('PaintingName','Name of painting'));
    $f->push(new TextField('PaintingDimensions','Dimensions of painting'));
    $f->push(new TextField('Media','Media'));
    $f->push(new CheckboxField('Sold','This painting is sold'));
    return $f;
    }
    }
    ?>

    /mysite/code/MyImageGalleryPage.php

    class MyImageGalleryPage extends ImageGalleryPage {
    protected $itemClass = "MyImageGalleryItem";
    }

    class MyImageGalleryPage_Controller extends ImageGallery_Controller {

    }

    For the Sold boolean, you just need to evaluate that on your template.

    <% if Sold %>sold<% else %>not sold<% end_if %>

    4705 Views
Page: 1 2 3 4
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.