1

I want to define a new template called "product".

This template calls an external service and retrieves the information about that specific product. That is easily done with a custom plugin that access the product information. Information on how to do that has been found here.

However, I would like that the URL of the page would be something like:

/product/<id>/<seo-friendly-description>

So I can retrieve in the Twig template both <id> and <seo-friendly-description> which will be used later to retrieve the specific product information.

I have tried to find something that could help in the documentation, without success. Could someone either point me to the right doc section or highlight the basic steps that shall be achieved so I can start solving this issue?

Just in case it helps, I am trying to find something similar to how bottle or other web frameworks work:

@route('/hello/<name>')
def greet(name):
    return 'Hello ' + name
M.E.
  • 4,955
  • 4
  • 49
  • 128

1 Answers1

1

I've been building a family recipebook into my own website and I've been working through a similar problem. I haven't quite worked out all the kinks, but my solution is mostly working if you want to checkout my github repo.

In short, you need the plugin to watch what the active route is. If the route matches, you then create the page and populate it using your plugin data.

I haven't quite figured out how to get the active page to highlight in the navigation menu for generated pages, but you might still find this solution helpful.

Jacobm001
  • 4,431
  • 4
  • 30
  • 51
  • Thanks I will give it a look. This is an actual issue with Grav which makes slightly difficult to deal with more complex projects. So far I have solved it by using the argument form of `/arg1:foo/arg2:bar` but I have the feeling of that being a workaround. I am extensively gathering information from external services in my last project, and I miss this specific plugin to deal with dynamic URLs in the Grav cookbook documentation section. – M.E. Mar 04 '18 at 14:16