<p>You can get all product types within your templates with:</p>

<pre><code>{% for productType in craft.commerce.productTypes %}
  {{ productType.name }}&lt;br&gt;
{% endfor %}
</code></pre>

<p>There is no way to get a specific product type within templates at the moment, but I have added to the list. In the meantime you would need to look over all and find the one you want as above.</p>

CC BY-SA 3.0
2016-03-21T18:45:56.323Z
Awesome, this is working great!  Thank you!

The only issue I have at this point is how to get the handle from productType, productType.handle doesn't seem to be working and the product type page in the docs isn't completed yet.
StrangeDevs
CC BY-SA 3.0
2016-03-21T18:02:39.927Z
2016-03-21T18:02:39.927Z
Luke Holder
<p>To expand on Luke's answer, you might try something like:</p>

<pre><code>&lt;form action=""&gt;
  &lt;select name="availableProductTypes"&gt;
     {% for theType in craft.commerce.productTypes %}
        &lt;option value="{{theType}}"&gt;{{theType.name}}&lt;/option&gt;
     {% endfor %}
  &lt;/select&gt;
  &lt;input type="submit" value="Show"&gt;
&lt;/form&gt;
</code></pre>

<p>Then you can show what was selected in the dropdown:</p>

<pre><code>{% if craft.request.getParam('availableProductTypes') %}

 {% set theType = craft.request.getParam('availableProductTypes') %}

 &lt;ul&gt;
  {% for product in craft.commerce.products.type(theType).find() %}
   &lt;li&gt;{{product}}&lt;/li&gt;
  {% else %}
   &lt;li&gt;No products found.&lt;/li&gt;
 {% endfor %}
 &lt;/ul&gt;

{% endif %}
</code></pre>

CC BY-SA 3.0
2016-03-21T19:08:24.370Z
2016-03-21T19:08:24.370Z
RitterKnight
<p>I am using Craft Commerce for the first time and am trying to dynamically generate a dropdown menu that contains links to each product type. I thought the best way to accomplish this would be by using a parameter in the URL i.e. </p>

<p>myurl.com/commerce/products?cat=books</p>

<p>I would be able to get the handle of the selected product type by using: </p>

<p><code>craft.commerce.products.type(productType).find()</code></p>

<p>I have two roadblocks that are preventing me from implementing this:</p>

<ol>
<li><p>How do I get an array of all the product types so I can build the dropdown?</p></li>
<li><p>How do I get the name of a product type once I have the handle so I can display a Header at the top of the page based on the selected product type?</p></li>
</ol>

<p>Also, is there a better way of implementing similar functionality that I am simply overlooking?</p>

<p>Thanks!</p>

<templating><plugin-craftcommerce>
Craft Commerce - Handling Product Types
# Craft Commerce - Handling Product Types

(Asked by: username_0 on 2016-03-21)

I am using Craft Commerce for the first time and am trying to dynamically generate a dropdown menu that contains links to each product type. I thought the best way to accomplish this would be by using a parameter in the URL i.e.

myurl.com/commerce/products?cat=books

I would be able to get the handle of the selected product type by using:

`craft.commerce.products.type(productType).find()`

I have two roadblocks that are preventing me from implementing this:

1. How do I get an array of all the product types so I can build the dropdown?
2. How do I get the name of a product type once I have the handle so I can display a Header at the top of the page based on the selected product type?

Also, is there a better way of implementing similar functionality that I am simply overlooking?

Thanks!

**Tags:** templating, plugin-craftcommerce


---

## 2 answers

### Answer by username_1 on 2016-03-21. Score: 1

You can get all product types within your templates with:
{% for productType in craft.commerce.productTypes %}
  {{ productType.name }}
{% endfor %}

There is no way to get a specific product type within templates at the moment, but I have added to the list. In the meantime you would need to look over all and find the one you want as above.

> **Comments:**
> **username_0**: Awesome, this is working great!  Thank you!  The only issue I have at this point is how to get the handle from productType, productType.handle doesn't seem to be working and the product type page in the docs isn't completed yet.  

---

### Answer by username_2 on 2016-03-21. Score: 1

To expand on Luke's answer, you might try something like:

  
     {% for theType in craft.commerce.productTypes %}
        {{theType.name}}
     {% endfor %}
  
  


Then you can show what was selected in the dropdown:
{% if craft.request.getParam('availableProductTypes') %}

 {% set theType = craft.request.getParam('availableProductTypes') %}

 
  {% for product in craft.commerce.products.type(theType).find() %}
   {{product}}
  {% else %}
   No products found.
 {% endfor %}
 

{% endif %}


---

