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

Plugin URL hook

Started by David 5 years ago · 2 replies · 488 views
5 years ago

Hello,
is it possible to listen for an url with a plugin/theme?
For example, I want to create an .ics file download and generate the files on the fly via php. I first placed an .php file in the main plugin directory, but couldn't access it via an url, which is great for security reasons!
But how can I achieve, that if for example the url htttps://website.tld/calender?item=123 whould result in a call of my plugin function which creates the downloadable file?
Best regards
David

5 years ago

I believe a sitemap plugin can be as an example for what you're looking for

PHP
/** @var Uri $uri */
$uri = $this->grav['uri'];
$route = $this->config->get('plugins.sitemap.route');

if ($route && $route == $uri->path()) {
    // Do your things
}
5 years ago

@redstone,

I first placed an .php file in the main plugin directory

This smells like a lack of insight in the concepts of plugins. You might want to take a look at the docs on plugins first to get a general idea of the concepts of plugins.

Then, using $ bin/plugin devtools new-plugin you can create a skeleton plugin in which you can give the code provided by @Karmalakas a try.

To get the query params have a look at the API in the docs: Uri::query()

last edited 07/26/21 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Slebeig, 5 days ago
1 106 5 days ago
Plugins · by Rene, 4 weeks ago
2 303 4 weeks ago
Plugins · by Xavier, 2 months ago
2 226 1 month ago
Plugins · by Luka Prinčič, 7 years ago
3 1415 2 months ago
Plugins · by Sebastian van de Meer, 2 months ago
1 323 2 months ago