From 8784372d4167fc85df13aeb2bcb3015e18359b48 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 1 Dec 2014 14:03:39 -0700 Subject: [PATCH] implemented a simple wildcard routing solution --- system/src/Grav/Common/Page/Pages.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 9b58304e6..53abfa6fc 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -236,14 +236,27 @@ class Pages // Fetch page if there's a defined route to it. $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null; - // If the page cannot be reached, look into site wide routes. + // If the page cannot be reached, look into site wide routes + wildcards if (!$all && (!$page || !$page->routable())) { /** @var Config $config */ $config = $this->grav['config']; + // See if route matches one in the site configuration $route = $config->get("site.routes.{$url}"); if ($route) { $page = $this->dispatch($route, $all); + } else { + // Try looking for wildcards + foreach ($config->get("site.routes") as $alias => $route) { + $match = rtrim($alias, '*'); + if (strpos($alias, '*') !== false && strpos($url, $match) !== false) { + $wildcard_url = str_replace('*', str_replace($match, '', $url), $route); + $page = isset($this->routes[$wildcard_url]) ? $this->get($this->routes[$wildcard_url]) : null; + if ($page) { + return $page; + } + } + } } }