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.

Archive /

Our old forums are still available as a read-only archive.

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

Image gallery


Go to End


5 Posts   4154 Views

Avatar
kpax

Community Member, 1 Post

21 March 2007 at 12:21pm

As far as I know there's no image gallery module available for SilverStripe yet, is there?
Would anyone know, in what way something like a gallery with custom fields for title, description, etc. could be created anyway for the time being?

thanks a lot

Avatar
MaryE

Community Member, 2 Posts

29 March 2007 at 3:18am

I too am intersted in such a module. I was thinking of building a page type -- done so for other CMS', but a module would be nice for mass uploading (from a zip), EXIF/IPTC/XMP extraction, thumbnail mgmt, etc. Just downloaded the CMS, so it may be sufficient to build page type.

M.

Avatar
Sean

Forum Moderator, 922 Posts

31 March 2007 at 3:29pm

Edited: 31/03/2007 3:36pm

The most basic gallery can be made using two custom page types:

GalleryHolder
GalleryPage

You first create a Gallery Holder in SilverStripe which can be used to show all photos as a landing page (if desired), then under the Gallery Holder you create Gallery Pages which are the individual gallery items.

Example:

GalleryHolder.php:
===============

<?php

class GalleryHolder extends Page {

// gallery pages are the default page to be created under a holder
static $default_child = "GalleryPage";

// only gallery pages are allowed under a holder section
static $allowed_children = array("GalleryPage");

/**
* Return the gallery pages with a limit you can set in template
* default is 5 if nothing set
*/
function GalleryItems($limit = 5) {
return DataObject::get("GalleryPage","`ParentID` = '{$this->ID}'", "", "", $limit);
}
}

GalleryPage.php:
==============

<?php

class GalleryPage extends Page {

// define your database fields here - for example we have author
static $db = array(
"Author" => "Varchar(100)"
);

// define image class relationships here (see Photo_GalleryImage class below)
static $has_one = array(
"Image" => "Photo_GalleryImage",
);

function getCMSFields($cms) {
$fields = parent::getCMSFields($cms);
$fields->addFieldToTab("Root.Content.Main", new TextField("Author","Photo author"));
$fields->addFieldToTab("Root.Content.Main", new ImageField("Image", "Photo"));
return $fields;
}
}

class GalleryPage_Image extends Image {

// define different GD functions to resize uploaded photos, see the GD page in the SilverStripe documentation for different functions for resampling

function generateThumbnail($gd) {
$gd->setQuality(90);
return $gd->resizeByWidth(288);
}
function generateNormal($gd) {
$gd->setQuality(90);
return $gd->resizeByWidth(395);
}
}

?>

You can then define some templates for these page types:

GalleryHolder.ss:
=============

<div id="Gallery">
<% if GalleryItems %>
<ul class="galleryList">
<!-- define limit in brackets -->
<% control GalleryItems(10) %>
<li>
<h3>$Title</h3>
<img src="$Image.Thumbnail.URL" alt="$Title photo" />
<p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>
</li>
<% end_control %>
</ul>
<% end_if %>
</div>

GalleryPage.ss:
============

<div id="Content">
<h2>$Title</h2>
<img src="$Image.Thumbnail.URL" alt="$Title photo" />
<p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>
</div>

You can get even fancier with pagination - ie. a results block with << Prev 1 2 3 Next >> etcetera, but this would be a good starting point if you're interested in making a gallery.

Avatar
MaryE

Community Member, 2 Posts

1 April 2007 at 11:15am

Edited: 01/04/2007 1:37pm

Thanks Sean for a quick start.

Am familiar with GD and you give me a good start with the classes to extend. I have also used phpThumb for display caching and might consider that if I get this thing going ...

However still having trouble installing, trying to follow a few other threads that are experiencing similar probs. (I've got XAMPP on local machine, figure 5.2 might be culprit, also had to muck w/ mySQL acct settings but got through that one).

M.

PS - not intending to start a separate thread on this, but it might be easier to give the option to have the admin set up the target DB, might save time in some cases. Still looks to be a great cms though, hope to get through this stuff.

Avatar
The Frenchy

Core Development Team, 40 Posts

21 September 2007 at 6:43pm

The version 0.2 has been released. check this.