10446 Posts in 2223 Topics by 1719 members
|Go to End|
17 September 2010 at 5:38am
Hello all. I'm using image_gallery_2.3 with SS 2.4.1 and I'm trying to dynamically create h1 selectors specific to each album, and obviously these CSS selectors need to be without spaces (i.e. slugized). So I would love to be able to call $URLSegment and get the name of the Album, but it only returns the main Photo Gallery SS page, which makes sense:
So I've added this function to ImageGalleryPage.php:
public function SlugizedAlbumTitle()
$str = $this->CurrentAlbum()->AlbumName;
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return rtrim($str, '-');
and it works just as I need, but obviously I'd much prefer to put a function in to my *own* code (e.g. /mysite/code/Page.php), but there I'm stumped. I've tried Director::URLParam('ID'), but with no magic.
Any tips would be greatly appreciated,
17 September 2010 at 6:17am
First, the album "slug" is just the Title property of the album's related folder.
Second, to generate slugs, just use SiteTree::generateURLSegment();
Lastly, rather than hacking the core of the module, just subclass it and add your custom method.
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com
|Go to Top|