Jump to:

11002 Posts in 2734 Topics by 1823 members

All other Modules

SilverStripe Forums » All other Modules » Trying to access slugized Album Name

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 738 Views
  • phawley
    Community Member
    21 Posts

    Trying to access slugized Album Name Link to this post

    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:


    returns photo-albums

    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,

  • UncleCheese
    4085 Posts

    Re: Trying to access slugized Album Name Link to this post

    Couple things..

    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

Page: 1
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.