Is there an easy way to check what the current page section type is, within a plugin?

I wonder if I'm overlooking a little function that simply returns: "single", "channel", "entry", etc...?


Thank you Aevlan, this was the approach I took originally. I've been struggling to determine wether the user is currently on the root of a channel/structure, or if they are on an entry page.

This is how I can determine "single", "channel" or "structure".

$element = craft()->urlManager->getMatchedElement();
$element_exists = $element && $element->getElementType() == ElementType::Entry;

$currentPageType = $element->section->type;

The reason I need to know this, is so I can perform some checks before I add certain navigation throughout the site. To help with my specific issue, I will use "hasDescendants()" or check the segment counts.

Thanks again. Mark

1 Answer 1


The SectionModel has a type property, which return what you're after, "single", "channel" and "entry". In a template it can be accessed like this:

{{ entry.section.type }}

If this is in a plugin and you have the section, you access it like this:


But I'm confused by the "current page" of your question. Maybe you can describe in a bit more detail what you're trying to achieve, and what your code looks like atm?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.