Is it possible to have a custom route with a custom controller for a certain page?
I mean, if i have a simple website but i’ve a certain page of the website that needs some PHP or something more complex than what i can achieve with “plain” grav page, is there the possiblity to do so?
Like a page that use some web service to do something, or to programmatically redirect people to somewhere given some conditions and so on.
I know that, even if that’s possible, then the menu integration is different theme to theme and i’ve to handle it case by case differently.
@FrancescoQ, As promised…
Grav allows plugins and themes to subscribe to events and execute custom php code to handle the event. During these events, users can be redirected, page content can be changed, etc. You name it…
Have a look at the docs about plugin basics, a tutorial, event hooks, and the Grav event lifecycle: https://learn.getgrav.org/plugins.
Here are the steps to create a new plugin:
- Install the devtools plugin:
$ bin/gpm install devtools
- Create a new plugin using a wizard:
$ bin/plugin devtools new-plugin
The newly created plugin subscribes to events and adds some text to the top of every page. Not very handy, but it gives you an idea of the skeleton of a plugin.
Once you have taken a look at the docs and the newly created plugin, and have some specific questions, please ask on the forum.
If you want an example of this, the Scholar-theme uses a custom Router to handle special-purpose routes affixed to the URL.
As pamtbaau says, you can intercept and manipulate any and all processing done by Grav in extensions.
Wow, thanks both! exactly what i was searching for! (i was debugging the admin plugin because i tought that it could do something similar to handle all the admin routes… )