Skip to main content
1 of 6
Douglas McDonald
  • 13.5k
  • 25
  • 57

The only thing I can think of off the top of my head is create custom routes in a plugin dynamically generated from your entryTypes, sectionHandles, and sectionHandle/entryTypes and then point them all to the same template, which would then either display the entries directly (via twig) or dynamically include a corresponding template, based on the handle.

Something like the following perhaps? Completely untested.

public function registerSiteRoutes() {

    // array to store all routes
    $routes = [];

    // get all section and entryTypes handles
    foreach(craft()->sections->getAllSections() as $section)
    {
        // add '/sectionHandle' routes
        $sectionHandle = $section->handle;
        $routes[$sectionHandle] = array('_dynamicTemplates/routeHandler.html');
    
        foreach($section->getEntryTypes() as $entryType)
        {
            // add '/entryTypeHandle' routes
            $entryTypeHandle = $entryType->handle;
            $routes[$entryTypeHandle] = array('_dynamicTemplates/routeHandler.html');
    
            // add '/sectionHandle/entryTypeHandle' routes
            $routes[$sectionHandle.'/'.$entryTypeHandle] = array('_dynamicTemplates/routeHandler.html');
        }
    }
    
    return $routes;

}

The one thing I don't know is if 'registerSiteRoutes()' gets called on every request, or only once when the plugin gets installed. If not, then you may also need to call it directly from an 'init()' method (or maybe just anytime an entry is saved - so it doesn't get fired on every request).

public function init() {
    parent::init();
    self::registerSiteRoutes();
}

The template would then grab the segments, perform an ECM search, and display results; or load a dynamic template based on the segments. Note: you might need to add an 'all' (or something else) to the solo 'entryTypeHandle' routes if there is any chance that your sectionHandle and entryType handle is the same. (i.e. '/all/entryTypeHandle').

Or the whole thing might not work also. Be interested to hear how it goes.

Douglas McDonald
  • 13.5k
  • 25
  • 57