Hi Grav team. First of all I must say I am growing more and more on your CMS and allthough I might have come up with some questions here on the forum I am finding myself getting more and more done with the system so there is barely anything that I cannot do without Grav.
But there is actually one thing where I am thinking of if that would be possible with Grav. Lets say I am fetching some kind of database (movies, books, whatever). Fetching the data with a plugin is not a problem but when it comes to constructing pages out these data I am a bit stuck. For example I get a JSON response from a data source with aprox. 300 entries. Listing all movies (or books) might be easy on a page like domain.com/movies
But is it possible to get the title from a movie and create a dynamic page url? (like domain.com/movie/some-dynamic-movie-titlewithout creating these pages manually in the file system?
I have compared this approach to other systems like Laravel where you can simply put a Wildcard ( something like {movie_url} )in the routing and the systems generates the pages based on the data. Thanks for letting me know and again - great work with Grav
This is possible, it’s basically how the admin plugin works. All those URLs you visit in the admin are not real pages, they are simply intercepted by the admin plugin and processed. There is no one-way to do this, but really you need to think about it a bit differently than in a traditional framework.
In those traditional frameworks, routing is the core of the whole process, where as in Grav, which has no advanced routing built-in, you have to build this logic in a plugin.
Because Grav doesn’t have a traditional router, you just inspect the URI in your plugin, parse it using either simple methods (explode on / ?) or more advanced methods (regex routing library ?), and then do ‘stuff’ based on what that route looks like.
Thanks, will check that out. What I recently tried was to play around with the URI params and tried to redirect something like www.domain.com/subpage/param:value/param2:value to www.domain.com/subpage/value/value2but that didn’t worked (see my other forum post about that).
I also found an approach to rewrite an URL like www.domain.com/page?id=1000¶m=valueto www.domain.com/page/1000/valuebut this didn’t worked as well and was throwing an error as the rewrite rules seems to be blocked by the other rewrite rules from the Grav system. However - I will look in to the flex-directory plugin as well and look for an approach.
Yah i would not use rewrites at this point. Simply create a plugin (like flex-directory) that can interpret and process the URL before Grav looks for a page.