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

Slash in url parameter

Solved by Ron Wardenier View solution

Started by T. 5 years ago · 8 replies · 1155 views
5 years ago

In my custom theme, I want to pass a parameter value containing a "Slash"

The parameter value is: Lab/abc and the route is "http:/mysite.com/tags/tag:Lab/abc".

  • The trouble is that the "/" between "Lab" & "abc" is considered as a new route. So it tries to reach a non existing route.

So I've tried to escape the "\" with the "url_encode" function, and it gives me another adress ""http:/mysite.com/tags/tag:Lab%2Fabc" but I'm still reaching a non existing route.

My question is : Is grav support "/" in parameter value ? or is it an advanced settings in Grav?

Thanks for help or suggestion.

5 years ago

Grav should not parse any URL parameter but it does when using the Grav URL parameter notation “key:value”.

A workaround is to use the standard “key=value”.

5 years ago

Hi bleutzinn,

unfortunatly the workaround does not work. "key=value" parameter format drives me to an unkwnown route, even with a regular parameter (no slash in it). Did I miss something?

5 years ago Solution

I assume the page tags exists.

Now when I use

TXT
http:/mysite.com/tags/tag:category/something

Grav gives me a 404.

When instead I use

TXT
http:/mysite.com/tags?tag=category/something

Grav just goes to the page tags.

5 years ago

@Raph31t , @bleutzinn ,

I don't think the 404 error is a matter of : or = but the preceding ? in front of the query paramers.

The : or = do however influence how the query is interpreted.

When using http://blog-dev/?tag:mush/room a dump of URI will show:

TXT
object: Grav\Common\Uri
url: "http://blog-dev/"
...
*query: "tag:mush/room"
*queries: Array(1)
  tag:mush/room: ""                             <-- note the difference
*params: Array(0)

When using http://blog-dev/?tag=mush/room a dump of URI will show:

YAML
object: Grav\Common\Uri
url: "http://blog-dev/"
...
*query: "tag=mush/room"
*queries: Array(1)
  tag: "mush/room"                               <-- note the difference
*params: Array(0)

Conclusion:

  • = gives the correct query parameters

Note:

  • When prepending the querystring with a ?, the plugin 'taxonomylist` won't work out of the box anymore.
last edited 02/10/21 by pamtbaau
5 years ago

Thanks it does the job. I've just change to get the tag value from the "uri.query" function and not the "uri.parameter" function.

5 years ago

Glad you got it working.

Just for future reference, the docs about the URI object distinguishes between 'URL parameter' and 'URL query'. The first being what I call Grav style key:value' or actually '/key:value and the second the standard way: ?key=value.

5 years ago

I noticed in the doc 2 days ago, and started to use the Grav syle, but because of the "/" trouble, I have switched to the standard way.

So you know why Grav has developped its own way ?

5 years ago

No I do not. It looks cool but I doubt that was the only reason

The problematic behavior you encountered is a bug in my opinion. I suggest you open an issue in the Grav core repository so the developers can fix it.

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 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago