i-lateral / silverstripe-filterable
Silverstripe module allowing creation of custom filters through the admin interface and then assigning to an object.
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 3
Type:silverstripe-module
Requires
Suggests
- silverstripe/cms: Add full content management support to your site
This package is auto-updated.
Last update: 2024-10-24 21:37:17 UTC
README
Module to allow creation of "Filters" that can be mapped to data objects.
The idea is that we then add ability to render these filters to front end templates and (eventually) add them to search results.
At the moment, only the backend mapping is supported by the module, front-end support comming soon...
Author
This module is created and maintained by ilateral
Contact: morven@i-lateral.com
Dependancies
- SilverStripe Framework 3.1.x
- Grid Field Extensions
Installation
Install this module either by downloading and adding to:
[silverstripe-root]/filterable
Then run: dev/build/?flush=all
Or alternativly add to your project's composer.json
Usage
Once installed, you can setup filters via the "Filters" tab in the CMS.
Mapping to objects
To be able to add filters to your objects, add the following to your _config.php
Filterable::add("YourObjectName", "RelationName");
- YourObjectName is the name of the object you want to add filters to.
- RelationName is the name of the relation added to the FilterOption object (for example, "Products").
Filtering on a controller
To be able to see a list of filtered objects from a controller, you need to add FilterableController to your controller classes. You can do this in either of the standard ways:
Via config.yml
YourController:
extensions:
- FilterableController
Via _config.php
YouController::add_extension("FilterableController");
Once a controller has been extended, it gains access to a "FilterMenu" and a "filterby" action.
Filter Menu
The Filter Menu can be loaded into a template using the template variable:
$FilterMenu
This generates a menu of available filters and options
Filter By
The "filterby" action returns a result set of objects, based on the relations you stipulate via Filterable::add().
These results are rendered into a template, you can overwrite this template in several ways.
-
Create a template called YourClassName_filterby.ss in your Layout This will allow you to create several different styled filters, depending on the controller.
-
Create a template called FilterBy.ss in your Layout directory.