silverstripe / silverstripe-dms

Adds a Document Management System to Silverstripe
BSD 3-Clause "New" or "Revised" License
40 stars 52 forks source link

Sort documents on frontend #7

Closed jeffwhitfield closed 11 years ago

jeffwhitfield commented 11 years ago

Hi there! Love the module! However, I'm banging my head on my desk trying to figure out how to sort the documents in a different order on the frontend. Any way to do this?

Thx a bunch! :)

candidasa commented 11 years ago

I haven't tried it myself, but be believe you can embed a GridField into the front-end of the site. GridField isn't just for the back-end CMS. However, it might take a bit of hacking around to get it working. If you also include the Sortable GridField add-on module, that should give you drag and drop sorting of documents in the front-end. Good luck!

If you can figure this out, please write some documentation for others and submit it as a pull request to the module.

jeffwhitfield commented 11 years ago

Hrm. Couldn't we just override the methods that are being use for the default include Documents in the template? Surely there's a way to enhance it to accept a field to sort by, right? That said, still having fun trying to figure out which methods control the output. Durp!

jeffwhitfield commented 11 years ago

Here's what's odd. I have the SortableGridField module installed and the DocumentSort value is getting stored right...but it's not being used at all in the "include Documents" output. :P

jeffwhitfield commented 11 years ago

Major, major durp! Figured it out! All you have to do is simply create a method in your controller using the getManyManyComponents method. Something like this works:

public function DocumentList(){
    $list = $this->getManyManyComponents('Documents')->sort('DocumentSort');
    return $list;
}

Then just use a Control loop in your template with DocumentList. Done! :)