<p>You can use the same approach as the link provided in your question. Only, instead of an entry, you're working with a <em>product</em>.</p>

<p>For example:</p>

<p><strong>template.twig</strong></p>

<pre><code>{# Get the current section - set fallback(s) for entries or products or ?? #}
{% set section = entry.getSection() | default(entry.getSection() ?? product.getType() ?? null) %}
{% if section %}
    {% set handle = section.handle %}
    {{ handle }} {# myProductType #}
{% endif %}
</code></pre>

<p>Here we are checking if we're on an entry. If not, we've set a fallback to check if we're on a product page. If nothing, the we return null.</p>

<p>Once we've got our section, we can check the handle. Then it's a matter of checking for the type you are looking for.</p>

<pre><code>...
{% if handle == 'myHandle' %}
    &lt;p&gt;We've got a winner!&lt;/p&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2017-02-04T21:01:00.187Z
2017-02-04T21:01:00.187Z
Damon
<p>I know there are ways to <a href="https://craftcms.stackexchange.com/questions/1682/get-the-current-section-handle">check current section</a>. I would like to check if I am on a specific product (commerce) page. </p>

<p>I am able to do this in a plugin by checking line item(s) and the product type. Is there a similar way to do the same at the twig level?</p>

<templating><plugin-craftcommerce>
Commerce: How can I check if I am on a specific product page?
# Commerce: How can I check if I am on a specific product page?

(Asked by: username_0 on 2017-02-04)

I know there are ways to [check current section](https://craftcms.stackexchange.com/questions/1682/get-the-current-section-handle). I would like to check if I am on a specific product (commerce) page.

I am able to do this in a plugin by checking line item(s) and the product type. Is there a similar way to do the same at the twig level?

**Tags:** templating, plugin-craftcommerce


---

## 1 answers

### Answer by username_0 on 2017-02-04. Score: 2 | Accepted answer

You can use the same approach as the link provided in your question. Only, instead of an entry, you're working with a product.
For example:
template.twig
{# Get the current section - set fallback(s) for entries or products or ?? #}
{% set section = entry.getSection() | default(entry.getSection() ?? product.getType() ?? null) %}
{% if section %}
    {% set handle = section.handle %}
    {{ handle }} {# myProductType #}
{% endif %}

Here we are checking if we're on an entry. If not, we've set a fallback to check if we're on a product page. If nothing, the we return null.
Once we've got our section, we can check the handle. Then it's a matter of checking for the type you are looking for.
...
{% if handle == 'myHandle' %}
    We've got a winner!
{% endif %}


---

