[Solved] Datasource: Return all items if there are no matches for a parameter value?
This is an open discussion with 2 replies, filed under General.
Search
is possible by customizing the datasource file
Correct. Inside the grab()
function you will want to check for the value of the URL parameter, and if it is "all-events" then remove any filtering on that field.
// "param" is the name of your URL Parameter if($this->_env['env']['url']['param'] == 'all') { // 123 is the ID of the field you are filtering on, // look at $dsParamFILTERS at the top of your data source unset($this->dsParamFILTERS[123]); };
Awesome, Nick, that works perfectly. Thanks!
Create an account or sign in to comment.
So I've got a standard datasources that filters by a page parameter, so if the parameter isn't set, all items are returned, and if the parameter is set only the item that matches the filter is returned.
What I really want is to have a generic value for the parameter that will also return all items. Is that possible?
E.g.
/events/event-1/
returns a match for "event-1" whereas/events/all-events/
returns all events, just as/events/
would. I'm trying to do this so that I can filter on a second parameter, e.g./events/all-events/city/
.I've got a sneaking suspicion that this is possible by customizing the datasource file, perhaps via
_force_empty_result
somehow? I'm just not very knowledgeable about PHP, unfortunately.