Skip to main content
replaced http://craftcms.stackexchange.com/ with https://craftcms.stackexchange.com/
Source Link

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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

Update: I see a potential problem. See this answerthis answer for possible solution. Not sure how to integrate it as part of the answer though. Perhaps send all requests to a controller action, and render the template from there. May have to leave it to you to try and resolve for now — sorry about that.

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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

Update: I see a potential problem. See this answer for possible solution. Not sure how to integrate it as part of the answer though. Perhaps send all requests to a controller action, and render the template from there. May have to leave it to you to try and resolve for now — sorry about that.

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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

Update: I see a potential problem. See this answer for possible solution. Not sure how to integrate it as part of the answer though. Perhaps send all requests to a controller action, and render the template from there. May have to leave it to you to try and resolve for now — sorry about that.

added 1 character in body
Source Link
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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

Update: I see a potential problem. See this answer for possible solution. Not sure how to integrate it as part of the answer though. Perhaps send all requests to a controller action, and render the template from there. May have to leave it to you to try and resolve for now — sorry about that.

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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

Update: I see a potential problem. See this answer for possible solution. Not sure how to integrate it as part of the answer though. Perhaps send all requests to a controller action, and render the template from there. May have to leave it to you to try and resolve for now — sorry about that.

added 1 character in body
Source Link
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 routes
    $routes = [];

    // get all section and entryType 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 include 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 ishandles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

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 routes
    $routes = [];

    // get all section and entryType 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 include 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').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

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 routes
    $routes = [];

    // get all section and entryType 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 include 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 handles are the same. (i.e. '/all/entryTypeHandle').

In theory anyway — the whole thing might not work also. Be interested to hear how it goes.

Note: there also may be some problems with my routes array. I've never tried creating a dynamic route to a template in this way (might need to explicitly add '/templates/'). If anyone sees a problem please feel free to edit the answer or leave a comment. Thanks.

added 221 characters in body
Source Link
Douglas McDonald
  • 13.5k
  • 25
  • 57
Loading
added 16 characters in body
Source Link
Douglas McDonald
  • 13.5k
  • 25
  • 57
Loading
Source Link
Douglas McDonald
  • 13.5k
  • 25
  • 57
Loading