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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Get querystring from Url in template

Solved by pamtbaau View solution

Started by Clay 6 years ago · 3 replies · 1301 views
6 years ago

Hello-

I am relatively new to Grav and I have built my first site with it, but I am trying some new ideas and I immediately ran into a problem: I didn't know how to fetch the query string from the URL when processing my twig templates.

I began combing the documentation, dumping out stuff with page|print_r and header|print_r and making wild guesses at other globals, google "grav query string" etc, but I couldn't find anything.

What is, if it is anything, the way to get at the query string when rendering a page?

And while we're here, what other global collections like "page" and "header" are available? (I couldn't find an explicit discussion of this in the docs).

Thank you very much.

6 years ago Solution

@claycle, Read some more docs.. ;-)

On doc page Theme Variables:

  • See Quick Menu for other theme variables
  • From the Quick Menu, try URI:

    The whole list of the Uri object methods is available on the API site. Here's a list of the methods you'll find most useful.<br><br>The Uri object has several methods to access parts of the current URI. For the full URL http://mysite.com/grav/section/category/page.json/param1:foo/param2:bar/?query1=baz&query2=qux

You'll find more details on classes on doc page Grav API:

last edited 08/30/20 by pamtbaau
6 years ago

AHA. Thank you. I never would have thought to look at "theme" variables as this seems more like "page" variables coming at it new.

Mindset altered.

Thank you.

6 years ago

@claycle, Well... it's mostly themes in which you create templates and use objects and variables... Maybe it should have been called "Template Variables".

Page variables? Nah, the variables are of all sorts: config (System, Site, Theme, Plugin, ...), Media, Taxonomy, User, ...

last edited 08/30/20 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 60 16 hours ago
Support · by Anna, 3 days ago
2 66 19 hours ago
Support · by Justin Young, 20 hours ago
1 34 20 hours ago
Support · by Duc , 1 week ago
2 70 6 days ago
Support · by Colin Hume, 1 week ago
2 61 6 days ago