You are here

README.txt in Views Contextual Range Filter 8

Same filename and directory in other branches
  1. 7 README.txt
CONTEXTUAL RANGE FILTER (D8/9)
==============================

This is a simple plugin for Views that adds the option to contextually filter
a view not just by a single value, but also by RANGE.

Just like normal contextual filters, contextual range filters may be set by
appending filter "arguments" to the URL. Examples follow below.

Integer, float, string and date ranges are supported.

Node and taxonomy term ids etc are special cases of integers so will work also.

You may use the OR ('+' to use multiple ranges). You can also the negate the
range(s), that is "exclude" rather than "include". You negate by ticking the 
"Exclude" box on the Views Contextual filter configuration panel, in the "More"
section.

To create a contextual range filter, first create a plain contextual filter as
per normal. I.e. in the Views UI open the "Advanced" field set (upper right) and
click "add" next to the heading "Contextual filters". On the next panel select
the field or property that needs to be contextually filtered and "Apply". Fill
out the configuration panel as you see fit, press "Apply" and "Save" the view.

Now visit the Contextual Range Filter configuration page,
admin/config/content/contextual-range-filter, find your contextual filter name
and tick the box left of it to turn the filter into a contextual range filter.
Press "Save configuration".

You apply contextual filters by appending "arguments" to the view's URL.
Using the double-hyphen '--' as a range separator, you can filter your view
output like so:

  http://yoursite.com/yourview/100--199.99  (numeric range)
  http://yoursite.com/yourotherview/k--qzz  (alphabetical range)
  http://yoursite.com/yourthirdview/2020-01-01--2020-06-30 (date range)
  http://yoursite.com/somebodysview/3--6    (list range, using list keys)

All ranges are inclusive of "from" and "to" values.

Wen using a date range you have the option to use "relative dates" as an
alternative to the strict YYYY-MM-DD format. For this tick the checkbox at the
bottom of the Contextual Filter pane in the Views UI. 
Not only does "relative dates" support phrases like "tomorrow" or "10 days ago",
it also supports more colloquial absolute date specifications, such as "20 Nov"
(this year).

You may omit the start or end values to specify open-ended filter ranges:

  http://yoursite.com/yourview/100--

Strings will be CASE-INSENSITIVE, unless your database defaults otherwise. In
your database's alphabet, numbers and special characters (@ # $ % etc.)
generally come before letters , e.g. "42nd Street" comes before "Fifth Avenue"
and also before "5th Avenue". The first printable ASCII character is the space
(%20). The last printable ASCII character is the tilde '~'. So to make sure
everything from "!Hello" and "@the Races" up to and including anything starting
with the letter r is returned, use " --r~".

Multiple contextual filters (e.g. Title followed by Price) are fine and if you
ticked "Allow multiple ranges" also, you can use the plus sign to OR 
filter-ranges like this:

  http://yoursite.com/yourotherview/a--e~+k--r~/--500
  
The above means a--e~ OR k--r~

Or, if your view has "Glossary mode" is on, so that only the first letter
matters, the above becomes:

  http://yoursite.com/yourotherview/a--e+k--r/--500

You may use a colon ':' instead of the double hyphen.
Use either '--', ':' or 'all' to return all View results for the associated
filter:

  http://yoursite.com/yourotherview/all/-100--999.99

You can opt to have URL arguments validated as numeric ranges in the Views UI
fieldset titled "When the filter value IS in the URL ...". Tick the "Specify
validation criteria" box and select the "Numeric Range" validator from the
drop-down. Just like core's "Numeric" validator, the "Numeric Range" validator
must not be selected if the "Allow multiple numeric ranges" box is ticked.
Instead select "-Basic Validation-".


Default Contextual Filter via PHP Code
--------------------------------------
Using a PHP Code snippet to produce a default contextual filter value comes in
very handy when you want to create a side bar of "related content" that is 
based on a range, rather than a single value, such as a taxonomy term.
Examples:
o Nearby locations
o Similarly priced products
o Blog posts published around the same time
For full examples, see:
https://medium.com/@rikdeboer/new-ways-to-display-related-content-with-views-in-drupal-8-9-2444a7a889e3


ASCII AND UTF CHARACTER ORDERING
o http://en.wikipedia.org/wiki/UTF-8

File

README.txt
View source
  1. CONTEXTUAL RANGE FILTER (D8/9)
  2. ==============================
  3. This is a simple plugin for Views that adds the option to contextually filter
  4. a view not just by a single value, but also by RANGE.
  5. Just like normal contextual filters, contextual range filters may be set by
  6. appending filter "arguments" to the URL. Examples follow below.
  7. Integer, float, string and date ranges are supported.
  8. Node and taxonomy term ids etc are special cases of integers so will work also.
  9. You may use the OR ('+' to use multiple ranges). You can also the negate the
  10. range(s), that is "exclude" rather than "include". You negate by ticking the
  11. "Exclude" box on the Views Contextual filter configuration panel, in the "More"
  12. section.
  13. To create a contextual range filter, first create a plain contextual filter as
  14. per normal. I.e. in the Views UI open the "Advanced" field set (upper right) and
  15. click "add" next to the heading "Contextual filters". On the next panel select
  16. the field or property that needs to be contextually filtered and "Apply". Fill
  17. out the configuration panel as you see fit, press "Apply" and "Save" the view.
  18. Now visit the Contextual Range Filter configuration page,
  19. admin/config/content/contextual-range-filter, find your contextual filter name
  20. and tick the box left of it to turn the filter into a contextual range filter.
  21. Press "Save configuration".
  22. You apply contextual filters by appending "arguments" to the view's URL.
  23. Using the double-hyphen '--' as a range separator, you can filter your view
  24. output like so:
  25. http://yoursite.com/yourview/100--199.99 (numeric range)
  26. http://yoursite.com/yourotherview/k--qzz (alphabetical range)
  27. http://yoursite.com/yourthirdview/2020-01-01--2020-06-30 (date range)
  28. http://yoursite.com/somebodysview/3--6 (list range, using list keys)
  29. All ranges are inclusive of "from" and "to" values.
  30. Wen using a date range you have the option to use "relative dates" as an
  31. alternative to the strict YYYY-MM-DD format. For this tick the checkbox at the
  32. bottom of the Contextual Filter pane in the Views UI.
  33. Not only does "relative dates" support phrases like "tomorrow" or "10 days ago",
  34. it also supports more colloquial absolute date specifications, such as "20 Nov"
  35. (this year).
  36. You may omit the start or end values to specify open-ended filter ranges:
  37. http://yoursite.com/yourview/100--
  38. Strings will be CASE-INSENSITIVE, unless your database defaults otherwise. In
  39. your database's alphabet, numbers and special characters (@ # $ % etc.)
  40. generally come before letters , e.g. "42nd Street" comes before "Fifth Avenue"
  41. and also before "5th Avenue". The first printable ASCII character is the space
  42. (%20). The last printable ASCII character is the tilde '~'. So to make sure
  43. everything from "!Hello" and "@the Races" up to and including anything starting
  44. with the letter r is returned, use " --r~".
  45. Multiple contextual filters (e.g. Title followed by Price) are fine and if you
  46. ticked "Allow multiple ranges" also, you can use the plus sign to OR
  47. filter-ranges like this:
  48. http://yoursite.com/yourotherview/a--e~+k--r~/--500
  49. The above means a--e~ OR k--r~
  50. Or, if your view has "Glossary mode" is on, so that only the first letter
  51. matters, the above becomes:
  52. http://yoursite.com/yourotherview/a--e+k--r/--500
  53. You may use a colon ':' instead of the double hyphen.
  54. Use either '--', ':' or 'all' to return all View results for the associated
  55. filter:
  56. http://yoursite.com/yourotherview/all/-100--999.99
  57. You can opt to have URL arguments validated as numeric ranges in the Views UI
  58. fieldset titled "When the filter value IS in the URL ...". Tick the "Specify
  59. validation criteria" box and select the "Numeric Range" validator from the
  60. drop-down. Just like core's "Numeric" validator, the "Numeric Range" validator
  61. must not be selected if the "Allow multiple numeric ranges" box is ticked.
  62. Instead select "-Basic Validation-".
  63. Default Contextual Filter via PHP Code
  64. --------------------------------------
  65. Using a PHP Code snippet to produce a default contextual filter value comes in
  66. very handy when you want to create a side bar of "related content" that is
  67. based on a range, rather than a single value, such as a taxonomy term.
  68. Examples:
  69. o Nearby locations
  70. o Similarly priced products
  71. o Blog posts published around the same time
  72. For full examples, see:
  73. https://medium.com/@rikdeboer/new-ways-to-display-related-content-with-views-in-drupal-8-9-2444a7a889e3
  74. ASCII AND UTF CHARACTER ORDERING
  75. o http://en.wikipedia.org/wiki/UTF-8