6

I don't suspect it's currently possible but I would be pleasantly surprised to find that it is.

I'm going to use an example from Django because I've seen it used there and a similar implementation would be handy to have in Craft. Annnnd it would be helpful for what we're trying to achieve with my current project.

Example: In Django you have your project-wide urls.py (think of this as routes.php in Craft). Additionally you can have app-specific URLs (an App might be a Blog or a Portfolio). You can define the app-specific paths in the app-specific urls.py file and then you can include those URLs in the project-wide URL file. That might look like this (example from the Django docs):

urlpatterns = [
    # ... snip ...
    url(r'^community/', include('django_website.aggregator.urls')),
    url(r'^contact/', include('django_website.contact.urls')),
    # ... snip ...
]

So a use-case:

We're developing a REST API and right now all of our routes are defined in routes.php. That's an ok solution, but we have a lot of plugin-specific routes. It would be nice to be able to define a base such as /api/ and pass the rest of the request to a plugin-specific routes file.

An idea of what this might look like:

return array(
    'api'   => array('pluginRoutes' => 'apiPluginName'),
);

And then in craft/plugins/apiPluginName/routes.php would be a routes file similar to the project-wide routes.php file in craft/config

2 Answers 2

13

Is the registerSiteRoutes hook what you're looking for?

1
  • I think this is exactly what I want :) Commented Jul 24, 2014 at 15:50
2

In Craft 3, you can accomplish this by hooking into the UrlManager::EVENT_REGISTER_SITE_URL_RULES event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.