<p>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.</p>

<p>Something like the following perhaps? Completely untested.</p>

<pre><code>public function registerSiteRoutes() {

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

    // get all section and entryType handles
    foreach(craft()-&gt;sections-&gt;getAllSections() as $section)
    {
        // add '/sectionHandle' routes
        $sectionHandle = $section-&gt;handle;
        $routes[$sectionHandle] = array('_dynamicTemplates/routeHandler.html');

        foreach($section-&gt;getEntryTypes() as $entryType)
        {
            // add '/entryTypeHandle' routes
            $entryTypeHandle = $entryType-&gt;handle;
            $routes[$entryTypeHandle] = array('_dynamicTemplates/routeHandler.html');

            // add '/sectionHandle/entryTypeHandle' routes
            $routes[$sectionHandle.'/'.$entryTypeHandle] = array('_dynamicTemplates/routeHandler.html');
        }
    }

    return $routes;

}
</code></pre>

<p>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).</p>

<pre><code>public function init() {
    parent::init();
    self::registerSiteRoutes();
}
</code></pre>

<p>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').</p>

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

<p>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.</p>

<p>Update: I see a potential problem. See <a href="https://craftcms.stackexchange.com/a/616/784">this answer</a> 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.</p>

CC BY-SA 3.0
2015-04-09T07:24:38.607Z
I'd love to test it, if I would have any experience building a plugin in Craft. Have never did that, so I'd be struggling over that first and than I could proceed to the test. Thank you for your answer, We can leave it open, till it gets solved.
Dominik Krulak
CC BY-SA 3.0
2015-04-10T02:13:47.793Z
A great starting place for developing your own plugin is to use a plugin template like [BusinessLogic](https://github.com/lindseydiloreto/craft-businesslogic), which provides an empty plugin framework complete with inline documentation, etc.
Douglas McDonald
CC BY-SA 3.0
2015-04-10T02:18:51.710Z
Btw... just a thought, but have you thought about using `categories` or some other device for creating the kind of cross-referenced structure that your looking for? Seems like a much easier way to do it, and shouldn't require the use of a plugin + more flexible, etc.
Douglas McDonald
CC BY-SA 3.0
2015-04-10T08:04:31.173Z
I may get back to start learning plugin way in Craft, but after I finish, What I've started. And thank you for pointing me to BusinessLogic.
Dominik Krulak
CC BY-SA 3.0
2015-04-10T08:07:33.363Z
Yes, I though about `categories`. But I also have considered the way I'm using now. It's more appropriate  to What I need.
Dominik Krulak
CC BY-SA 3.0
2015-04-08T19:17:56.610Z
2015-04-08T19:42:41.213Z
2017-04-13T12:51:00.253Z
Douglas McDonald
<p>There is the one way to build it, I could know, but It's complicated for maintenance, because I may add some new entry by time.</p>

<p>I'm trying to figure out a better way to have entry types related to a section and all sections in dropdown menu. <strong>Namely, sections have some same, some different entry types</strong>. So, when I click at any entry type at current section page, I get all those related entries to the click. It's more like filter feature, but except filtering on current page, you get redirected to a page with selected entry type's option.</p>

<p>Better to visualize it:</p>

<p>(<a href="http://www.dev.craft/" rel="nofollow">http://www.dev.craft/</a> = all entry's types from all sections) = all entries from all sections and entry's types.</p>

<p>(<a href="http://www.dev.craft/entryTypeHandle" rel="nofollow">http://www.dev.craft/entryTypeHandle</a> = entryTypeHandle from all sections) = entries from all sections and entryTypeHandel.</p>

<p>(<a href="http://www.dev.craft/sectionHandle/entryTypeHandle" rel="nofollow">http://www.dev.craft/sectionHandle/entryTypeHandle</a>) = entries from sectionHandle and entryTypeHandle</p>

<p>It is hard to read. You're welcome for question's comments, if anything unclear.</p>

<entry-type>
Dropdown menu out of entry types
# Dropdown menu out of entry types

(Asked by: username_0 on 2015-04-08)

There is the one way to build it, I could know, but It's complicated for maintenance, because I may add some new entry by time.

I'm trying to figure out a better way to have entry types related to a section and all sections in dropdown menu. **Namely, sections have some same, some different entry types**. So, when I click at any entry type at current section page, I get all those related entries to the click. It's more like filter feature, but except filtering on current page, you get redirected to a page with selected entry type's option.

Better to visualize it:

(<http://www.dev.craft/> = all entry's types from all sections) = all entries from all sections and entry's types.

(<http://www.dev.craft/entryTypeHandle> = entryTypeHandle from all sections) = entries from all sections and entryTypeHandel.

(<http://www.dev.craft/sectionHandle/entryTypeHandle>) = entries from sectionHandle and entryTypeHandle

It is hard to read. You're welcome for question's comments, if anything unclear.

**Tags:** entry-type


---

## 1 answers

### Answer by username_1 on 2015-04-08. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: I'd love to test it, if I would have any experience building a plugin in Craft. Have never did that, so I'd be struggling over that first and than I could proceed to the test. Thank you for your answer, We can leave it open, till it gets solved.  
> **username_1**: A great starting place for developing your own plugin is to use a plugin template like [BusinessLogic](https://github.com/lindseydiloreto/craft-businesslogic), which provides an empty plugin framework complete with inline documentation, etc.  
> **username_1**: Btw... just a thought, but have you thought about using `categories` or some other device for creating the kind of cross-referenced structure that your looking for? Seems like a much easier way to do it, and shouldn't require the use of a plugin + more flexible, etc.  
> **username_0**: I may get back to start learning plugin way in Craft, but after I finish, What I've started. And thank you for pointing me to BusinessLogic.  
> **username_0**: Yes, I though about `categories`. But I also have considered the way I'm using now. It's more appropriate  to What I need.  

---

