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.

Themes & Styling

Is uri.query() not working on static pages without php?

theme

Solved by Ole Vik View solution

Started by Christiana 5 years ago · 6 replies · 740 views
5 years ago

Hi!

I use the theme variable uri.query to add params from current url to an form url string. On local development environment everything works fine.

TWIG
{% set uriParams = uri.query != '' ? '&' ~ uri.query %}
{% set form_url = button.link_extern ~ h2Params ~ lpidParam ~ uriParams %}

On the static exported live site on server without php uri.query does'nt give any params.
Is php required for this function?

The theme variable uri.route works on both systems.

I'm looking forward to an answer!
Christiana

5 years ago

I thought PHP is requierd for Grav to work at all 😕

5 years ago

@Karmalakas for working with admin panel e.g. you need php. But you can provide an static exported website to your visitors on another server for example.
There are several plugins you can use to generate a static export like blackhole.
https://github.com/BarryMode/grav-plugin-blackhole

We use this way to have a high security level.

5 years ago

Oh I see :) My guess...

uri.route is taken from Grav core where it parses page structure and frontmatter of each page to get slugs and what not. uri.query most likely taken from GLOBALS (probably $_REQUEST), so that might be the reason it's empty on export. Query I guess is something you entered in some filter field or so and exporter definitely wouldn't export such pages.

5 years ago

Ok. So uri.query() is based on php. I used it to get query params of current page url in twig template and added them to a string. Then I have to do it in another way...perhaps javascript.

5 years ago Solution

Yep, every Grav internal is PHP. uri.query() renders server-side, but it's easy to replace in JavaScript. An example in Scholar.

👍 2
5 years ago

JavaScript to get all query params as string:

JS
urlParams = new URLSearchParams(window.location.search);
urlParamsString =  urlParams.toString();

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 90 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 449 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 44 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 123 3 months ago