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.

Plugins

Plugin URL hook

Started by David 5 years ago · 2 replies · 436 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 Rene, 1 week ago
2 49 1 week ago
Plugins · by Xavier, 4 weeks ago
2 57 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1184 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 75 2 months ago