diff --git a/inc/template.php b/inc/template.php
index 7309c9b32280360a9f1c378c66bb787b03c816f6..66cbbe471a7b390fecc70b56f66a8e7318799b80 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -1746,5 +1746,23 @@ function tpl_media() {
     echo '</div>'.NL;
 }
 
+/**
+ * Return useful layout classes
+ *
+ * @author Anika Henke <anika@selfthinker.org>
+ */
+function tpl_classes() {
+    global $ACT, $conf, $ID, $INFO;
+    $classes = array(
+        'dokuwiki',
+        'mode_'.$ACT,
+        'tpl_'.$conf['template'],
+        $_SERVER['REMOTE_USER'] ? 'loggedIn' : '',
+        $INFO['exists'] ? '' : 'notFound',
+        ($ID == $conf['start']) ? 'home' : '',
+    );
+    return join(' ', $classes);
+}
+
 //Setup VIM: ex: et ts=4 :
 
diff --git a/lib/tpl/dokuwiki/detail.php b/lib/tpl/dokuwiki/detail.php
index 76a6c71408697e72cff102ed6e82370c5f05742d..7e46231d38226aae5c5e3698c3dc3c250892d696 100644
--- a/lib/tpl/dokuwiki/detail.php
+++ b/lib/tpl/dokuwiki/detail.php
@@ -28,8 +28,8 @@ header('X-UA-Compatible: IE=edge,chrome=1');
 
 <body>
     <!--[if lte IE 7 ]><div id="IE7"><![endif]--><!--[if IE 8 ]><div id="IE8"><![endif]-->
-    <div id="dokuwiki__site"><div id="dokuwiki__top"
-        class="dokuwiki site mode_<?php echo $ACT ?>">
+    <div id="dokuwiki__site"><div id="dokuwiki__top" class="site <?php echo tpl_classes(); ?> <?php
+        echo ($showSidebar) ? 'showSidebar' : ''; ?> <?php echo ($hasSidebar) ? 'hasSidebar' : ''; ?>">
 
         <?php include('tpl_header.php') ?>
 
diff --git a/lib/tpl/dokuwiki/main.php b/lib/tpl/dokuwiki/main.php
index 712d011754ed53a7fd74a6f914a513ef93121e55..9e507d86d095725c5af2d65ae35985d779204a35 100644
--- a/lib/tpl/dokuwiki/main.php
+++ b/lib/tpl/dokuwiki/main.php
@@ -27,9 +27,8 @@ $showSidebar = $hasSidebar && ($ACT=='show');
 
 <body>
     <!--[if lte IE 7 ]><div id="IE7"><![endif]--><!--[if IE 8 ]><div id="IE8"><![endif]-->
-    <div id="dokuwiki__site"><div id="dokuwiki__top"
-        class="dokuwiki site mode_<?php echo $ACT ?> <?php echo ($showSidebar) ? 'showSidebar' : '';
-        ?> <?php echo ($hasSidebar) ? 'hasSidebar' : ''; ?>">
+    <div id="dokuwiki__site"><div id="dokuwiki__top" class="site <?php echo tpl_classes(); ?> <?php
+        echo ($showSidebar) ? 'showSidebar' : ''; ?> <?php echo ($hasSidebar) ? 'hasSidebar' : ''; ?>">
 
         <?php include('tpl_header.php') ?>