<p>One thing that’s important to remember is that there’s no inherent relationship between your templates and sections. Any template can show any entry from any section. So there’s no such thing as the “current section”.</p>

<p>If your section has the “Entries in this section have their own URLs” setting checked, and you’re requesting one of that section’s entries’ URLs, then the section’s template will get loaded automatically and an <code>entry</code> variable will be available to it, which represents the entry whose URL you requested. But that doesn’t mean that you couldn’t have loaded the same template some other way (e.g. via an <a href="http://buildwithcraft.com/docs/templating/craft.entries"><code>{% include %}</code></a> tag from another template), or that you couldn’t have manually fetched that entry some other way (e.g. with <a href="http://buildwithcraft.com/docs/templating/craft.entries"><code>craft.entries</code></a>).</p>

<p>Anyway, if you have an <a href="http://buildwithcraft.com/docs/templating/entrymodel">EntryModel</a> variable set (such as that <code>entry</code> variable that you’d automatically get when accessing an entry’s URL), you can access it’s section using <a href="http://buildwithcraft.com/docs/templating/entrymodel#getSection"><code>entry.getSection()</code></a>, and you can access that section’s handle via its <a href="http://buildwithcraft.com/docs/templating/sectionmodel#handle"><code>handle</code></a> property.</p>



<pre class="lang-twig prettyprint-override"><code>{% set section = entry.getSection() %}
{% set handle = section.handle %}
</code></pre>

<p>That could be simplified to:</p>

<pre class="lang-twig prettyprint-override"><code>{% set handle = entry.getSection().handle %}
</code></pre>

<p>or even:</p>

<pre class="lang-twig prettyprint-override"><code>{% set handle = entry.section.handle %}
</code></pre>

CC BY-SA 4.0
2022-02-16T14:17:11.790Z
I know this is an old question, but I can't get this to work properly in a multisite environment. All I get out is the "main" handle, when I need to localized handle.
InanisAtheos
CC BY-SA 3.0
2014-08-08T11:15:08.937Z
Nice, thank you!
While this works for exactly what I need... I can see why this isn't always the best approach to assign each page with a generic class. The idea is just help with styling. 

I wonder (for future reference), how I might be able to get the same information via a plugin? Do you know of a PHP method?

Thanks again :)
Mark Notton
CC BY-SA 3.0
2014-08-08T12:35:10.130Z
You can get the matched entry [like so](http://craftcms.stackexchange.com/questions/1715/how-can-i-get-the-requested-entry-from-a-plugin/1716#1716), and if there is one, you can access its section’s handle via `$element->getSection()->handle`.
Brandon Kelly
CC BY-SA 3.0
2014-08-07T10:40:04.307Z
2014-08-07T10:40:04.307Z
Brandon Kelly
<p>I can't help but think this is a silly/obvious question, but I'm trying to retrieve the current section handle so I can use it as a class. </p>

<p>Maybe I'm going about it wrong, but {{ handle }} does nothing. </p>

<p>Any ideas?</p>

<templating><entry><sections>
Get the current section handle
# Get the current section handle

(Asked by: username_0 on 2014-08-07)

I can't help but think this is a silly/obvious question, but I'm trying to retrieve the current section handle so I can use it as a class.

Maybe I'm going about it wrong, but {{ handle }} does nothing.

Any ideas?

**Tags:** templating, entry, sections


---

## 1 answers

### Answer by username_1 on 2014-08-07. Score: 23 | Accepted answer

One thing that’s important to remember is that there’s no inherent relationship between your templates and sections. Any template can show any entry from any section. So there’s no such thing as the “current section”.
If your section has the “Entries in this section have their own URLs” setting checked, and you’re requesting one of that section’s entries’ URLs, then the section’s template will get loaded automatically and an entry variable will be available to it, which represents the entry whose URL you requested. But that doesn’t mean that you couldn’t have loaded the same template some other way (e.g. via an {% include %} tag from another template), or that you couldn’t have manually fetched that entry some other way (e.g. with craft.entries).
Anyway, if you have an EntryModel variable set (such as that entry variable that you’d automatically get when accessing an entry’s URL), you can access it’s section using entry.getSection(), and you can access that section’s handle via its handle property.
{% set section = entry.getSection() %}
{% set handle = section.handle %}

That could be simplified to:
{% set handle = entry.getSection().handle %}

or even:
{% set handle = entry.section.handle %}

> **Comments:**
> **username_0**: Nice, thank you! While this works for exactly what I need... I can see why this isn't always the best approach to assign each page with a generic class. The idea is just help with styling.   I wonder (for future reference), how I might be able to get the same information via a plugin? Do you know of a PHP method?  Thanks again :)  
> **username_1**: You can get the matched entry [like so](http://craftcms.stackexchange.com/questions/1715/how-can-i-get-the-requested-entry-from-a-plugin/1716#1716), and if there is one, you can access its section’s handle via `$element->getSection()->handle`.  
> **username_2**: I know this is an old question, but I can't get this to work properly in a multisite environment. All I get out is the "main" handle, when I need to localized handle.  

---

