urlparamfilter
is a simple Grav plugin that adds filters for accessing and manipulating URL-Parameters, Query-Strings and URL-Fragments in Templates.
Installing the URL-Parameter plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:
bin/gpm install URL-Parameter
This will install the URL-Parameter plugin into your /user/plugins
directory within Grav. Its files can be found under /your/site/grav/user/plugins/urlparamfilter
.
To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins
. Then, rename the folder to urlparamfilter
. You can find these files either on GitHub or via GetGrav.org.
You should now have all the plugin files under
/your/site/grav/user/plugins/urlparamfilter
NOTE: This plugin is a modular component for Grav which requires Grav to function
This Plugin provides Three filters which can all be used for different tasks, depending on the provided set of parameters:
Returns a Dictionary with all Query-Parameters
{{ '/some/url?foo=bar&moo=quu' | query() | dump }}
=> array('foo' => 'bar', 'moo' => 'quu')
Returns the Value of the Specified Query-Parameter
{{ '/some/url?foo=bar&moo=quu' | query('moo') | dump }}
=> 'quu'
Appends the Specified Key and Value to the URL
{{ '/some/url?foo=bar' | query('moo', 'quu') | dump }}
=> '/some/url?foo=bar&moo=quu'
{{ '/some/url?foo=bar' | query('moo', '') | dump }}
=> '/some/url?foo=bar&moo='
Removes the Specified Key and Value from the URL
{{ '/some/url?foo=bar&moo=quu' | query('moo', 'false') | dump }}
=> '/some/url?foo=bar'
Appends the Specified Key-Value-Pairs to the URL
{{ '/some/url' | query({'foo': 'bar', 'moo': 'quu'}) | dump }}
=> '/some/url?foo=bar&moo=quu'
Returns a Dictionary with all Query-Parameters
{{ '/some/url/foo:bar/moo:quu' | param() | dump }}
=> array('foo' => 'bar', 'moo' => 'quu')
Returns the Value of the Specified Query-Parameter
{{ '/some/url/foo:bar/moo=quu' | param('moo') | dump }}
=> 'quu'
Appends the Specified Key and Value to the URL
{{ '/some/url/foo:bar' | param('moo', 'quu') | dump }}
=> '/some/url/foo:bar/moo:quu'
{{ '/some/url/foo:bar' | param('moo', '') | dump }}
=> '/some/url/foo:bar/moo:'
Removes the Specified Key and Value from the URL
{{ '/some/url/foo:bar' | param('moo', false) | dump }}
=> '/some/url/foo:bar'
Appends the Specified Key-Value-Pairs to the URL
{{ '/some/url' | param({'foo': 'bar', 'moo': 'quu'}) | dump }}
=> '/some/url/foo:bar/moo:quu'
Returns the Fragment-Text
{{ '/some/url#moo' | fragment() | dump }}
=> 'moo'
Set the specified Fragment
{{ '/some/url' | fragment('moo') | dump }}
=> '/some/url#moo'