Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Parsing URL parameters

Started by Muut Archive 11 years ago · 2 replies · 1551 views
11 years ago

How would I go about parsing URL parameters in a Twig template? Say I had a page that was access with like the following /grav/page/?red=255&green=255&blue=255, how could I access the values of these parameters by keys? I'm assuming, of course, that Twig extends PHP far enough to allow for maps, ie. indexed or associative arrays.

11 years ago

you can pass query parameters this way:

TWIG
{{ uri.query('red') }}

or you can use the cleaner looking grav specific params.

TXT
http://yourgravsite.com/red:255/green:150/blue:102

Then to access them you use the URI object which is available in Twig:

TWIG
{{ uri.param('red') }}}
11 years ago

Ah, I was unaware that the query function took parameters of its own, thanks!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1327 9 years ago
Archive · by Muut Archive, 9 years ago
2 921 9 years ago
Archive · by Muut Archive, 9 years ago
2 4050 9 years ago
Archive · by Muut Archive, 9 years ago
1 2928 9 years ago
Archive · by Muut Archive, 9 years ago
3 1107 9 years ago